PHP 5.4
Michał Pipa
20 września 2012
Michał Pipa
20 września 2012
break 1 + foo() * $bar;
)<?php function foo() { return array(1, 2, 3); } echo foo()[2];
<?php $foo = function() { return array(1, 2, 3); }; echo $foo()[0];
(new Foo)->bar()
(new Foo)->bar
$array = [1, 2, 3, 4]; $array = array( "foo" => "bar", "bar" => "foo", ); $array = [ "foo" => "bar", "bar" => "foo", ];
trait ezcReflectionReturnInfo { function getReturnType() { /*1*/ } function getReturnDescription() { /*2*/ } } class ezcReflectionMethod extends ReflectionMethod { use ezcReflectionReturnInfo; /* ... */ } class ezcReflectionFunction extends ReflectionFunction { use ezcReflectionReturnInfo; /* ... */ }
class Base { public function sayHello() { echo 'Hello '; } } trait SayWorld { public function sayHello() { parent::sayHello(); echo 'World!'; } } class MyHelloWorld extends Base { use SayWorld; }
trait Hello { public function sayHello() { echo 'Hello '; } } trait World { public function sayWorld() { echo 'World'; } } class MyHelloWorld { use Hello, World; public function sayExclamationMark() { echo '!'; } }
trait A { public function smallTalk() { echo 'a'; } public function bigTalk() { echo 'A'; } } trait B { public function smallTalk() { echo 'b'; } public function bigTalk() { echo 'B'; } }
class Talker { use A, B { B::smallTalk insteadof A; A::bigTalk insteadof B; } } class Aliased_Talker { use A, B { B::smallTalk insteadof A; A::bigTalk insteadof B; B::bigTalk as talk; } }
$ php -S localhost:8000
PHP 5.4.8-dev Development Server started at Thu Sep 20 04:13:04 2012 Listening on http://localhost:8000 Document root is /tmp Press Ctrl-C to quit.
$ php -S localhost:8000 router.php
router.php
<?php if (preg_match('/\.(?:png|jpg|gif)$/', $_SERVER["REQUEST_URI"])) { return false; } else { echo "<p>Welcome to PHP</p>"; } ?>
Nie należy korzystać z tego serwera w środowisku produkcyjnym!
0b10101
public function test_callable(callable $callback, $data) { call_user_func($callback, $data); }