PHP code example of phpfn / symbol
1. Go to this page and download the library: Download phpfn/symbol library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
phpfn / symbol example snippets
$a = symbol();
// OR
$b = \Fun\Symbol\Symbol::create();
$symbol = symbol('id');
var_dump(symbol() === symbol());
// expected output: false
var_dump(symbol('example') === symbol('example'));
// expected output: false
define('EXAMPLE', symbol());
var_dump(is_symbol(EXAMPLE));
// expected output: true
class Example
{
public const CLASS_CONST = EXAMPLE;
}
var_dump(is_symbol(Example::CLASS_CONST));
// expected output: true
serialize(symbol());
// Error
var_dump(is_string(symbol()));
// expected output: false
var_dump(is_int(symbol()));
// expected output: false
var_dump(is_float(symbol()));
// expected output: false
var_dump(is_bool(symbol()));
// expected output: false
var_dump(is_array(symbol()));
// expected output: false
var_dump(is_object(symbol()));
// expected output: false
var_dump(is_null(symbol()));
// expected output: false
var_dump(is_symbol(symbol()));
// expected output: true
var_dump(is_resource(symbol()));
// expected output: true
$a = symbol();
$b = $a;
var_dump($a === $b);
// expected output: true
var_dump(clone $a);
// Error
use Fun\Symbol\Symbol;
var_dump(Symbol::key(symbol('hello')));
// expected output: "hello"
var_dump(Symbol::key(symbol('hello')) === Symbol::key(symbol('hello')));
// expected output: true
var_dump(symbol('hello') === symbol('hello'));
// expected output: false
use Fun\Symbol\Symbol;
$reflection = Symbol::getReflection(Symbol::create('hello'));
$reflection->getName(); // Contains "hello" string
$reflection->getFileName(); // Provides path/to/file-with-symbol-definition.php
$reflection->getStartLine(); // Provides definition line
// etc...
use Fun\Symbol\Symbol;
var_dump(Symbol::for('a') === Symbol::for('a'));
// expected output: true
var_dump(Symbol::create('a') === Symbol::for('a'));
// expected output: false
var_dump(Symbol::keyFor(Symbol::for('a')));
// expected output: "a"
var_dump(Symbol::keyFor(Symbol::create('a')));
// expected output: null