Created
March 8, 2012 08:51
-
-
Save marek-saji/1999745 to your computer and use it in GitHub Desktop.
new stuff in php 5.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* `<?=` jest zawsze dostępny, niezależnie od ustawienia `short_open_tag` | |
*/ | |
/** | |
* use newly created object on the fly | |
*/ | |
$this->addFoo( | |
(new HGZ_Foo)->setStuff($stuff) | |
); | |
/** | |
* use {} to specify static method names | |
*/ | |
$method = 'method'; | |
$tst = new Test(); | |
$tst->method() === $tst->$method() === $tst->{'method'}(); | |
Test::method() === Test::$method() === Test::{'method'}(); // last one is new | |
/** | |
* function result's index! | |
*/ | |
function fruit () { | |
return array('a' => 'apple', 'b' => 'banana'); | |
} | |
echo fruit()['a']; | |
/** | |
* `callable` typehint: everything that `is_callable` | |
*/ | |
function foo(callable $cb) { | |
$cb(); | |
} | |
/** | |
* calling *all* the `callable`s | |
*/ | |
$foo = array($obj, 'method'); $foo(); | |
$foo = 'func'; $foo(); | |
$foo instanceof Closure; $foo(); | |
/** | |
* short array syntax | |
*/ | |
$a = [1, 2, 3]; | |
$b = ['foo' => 'orange', 'bar' => 'apple', 'baz' => 'lemon']; | |
/** | |
* binary notation | |
*/ | |
$x = 0b001110; | |
echo $x; | |
/** | |
* traits | |
*/ | |
class Base { | |
public function sayHello() { | |
echo 'Hello'; | |
return $this; | |
} | |
} | |
trait SayWorld { | |
public function sayHello() { | |
parent::sayHello(); | |
echo ' World'; | |
return $this; | |
} | |
public function emphasise() { | |
echo '!'; | |
} | |
} | |
trait Internet { | |
public function emphasise() { | |
echo '!!!shiftplusone'; | |
} | |
} | |
class MyHelloWorld extends Base { | |
use SayWorld, Internet; | |
} | |
$o = new MyHelloWorld(); | |
$o->sayHello()->emphasise(); // prints "Hello World!!!shiftplusone"; | |
// much more on traits: http://php.net/manual/en/language.oop5.traits.php | |
/** | |
* Native upload process | |
*/ | |
?> | |
<form action="upload.php" method="POST" enctype="multipart/form-data"> | |
<input type="hidden" name="<?= ini_get("session.upload_progress.name") ?>" value="kewlUpload" /> | |
<input type="file" name="file1" /> | |
<input type="file" name="file2" /> | |
<input type="submit" /> | |
</form> | |
<?php | |
$key = ini_get("session.upload_progress.prefix") . ini_get("session.upload-progress.name"); | |
$_SESSION[$key]; // data about uploading | |
// more on that: http://docs.php.net/manual/en/session.upload-progress.php | |
/** | |
* Added built-in web server that is intended for testing purpose. | |
*/ | |
`php -S localhost:8000`; | |
// or | |
`php -S localhost:8000 router.php`; | |
// more on that: http://www.php.net/manual/en/features.commandline.webserver.php | |
/** | |
* Lots of performance and memory usage improvements | |
* including improved performance of @ (silence) operator. | |
*/ | |
/** | |
* Improved parse error messages and improved incompatible arguments warnings. | |
*/ | |
// sources: http://php.net/releases/5_4_0.php | |
// http://php.webtutor.pl/en/2011/09/27/whats-new-in-php-5-4-a-huge-list-of-major-changes/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment