Skip to content

Instantly share code, notes, and snippets.

@phpdave
Created June 15, 2015 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpdave/71274b09326644e2c7be to your computer and use it in GitHub Desktop.
Save phpdave/71274b09326644e2c7be to your computer and use it in GitHub Desktop.
Testing PHP7 Alpha 's new features in windows command line (cmd.exe)
<?
//Testing PHP7 new features in windows command line
echo PHP_EOL;
//Null Coalesce Operator
echo '#### Null Coalesce Operator ####'. PHP_EOL;
$arguments[] = $argv[0];//Script Name (c:\PHP7\scripts\test.php)
$arguments[] = $argv[1] ?? "DefaultValue";//If we don't pass 2nd argument we'll set it to zero using the new Null Coalesce Operator
var_dump($arguments);
echo PHP_EOL . PHP_EOL;
//Unicode Codepoint Escape Syntax
echo '#### Unicode Codepoint Escape Syntax ####'. PHP_EOL;
echo "ma\u{00F1}ana". PHP_EOL; // pre-composed character
echo "man\u{0303}ana". PHP_EOL; // "n" with combining ~ character (U+0303)
echo PHP_EOL . PHP_EOL;
//Closure::call
echo '#### Closure::call ####'. PHP_EOL. PHP_EOL;
class Foo { private $x = 3; }
$foo = new Foo;
$foobar = function () { var_dump($this->x); };
$foobar->call($foo); // prints int(3)
echo PHP_EOL . PHP_EOL;
//Speed Test
echo '#### Speed Test ####'. PHP_EOL. PHP_EOL;
$before = microtime(true);
for ($i=0 ; $i<100000 ; $i++) {
serialize($arguments);
}
$after = microtime(true);
echo ($after-$before)/$i . " sec/serialize\n";
echo PHP_EOL . PHP_EOL;
//try-catch of a member function of a non-object
//::NOTE:: Possible bug - Not working for me on Windows Command line 32 bit - https://wiki.php.net/rfc/catchable-call-to-member-of-non-object
echo '#### try-catch of a member function of a non-object ####'. PHP_EOL. PHP_EOL;
set_error_handler(function($code, $message) {
var_dump($code, $message);
});
$x= null;
var_dump($x->method());
echo "Alive\n";
echo PHP_EOL . PHP_EOL;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment