Last active
December 11, 2015 19:58
-
-
Save bennuttall/4652096 to your computer and use it in GitHub Desktop.
Code snippets from PHP 5.4 blog post
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 | |
// PHP 5.3 | |
$arr = array(); | |
$arr2 = array('a','b','c'); | |
$arr3 = array('a' => 2, 'b' => 4, 'c' => 8); | |
$arr4 = array(array('abc','def'), array(2,4,8), 16); | |
// PHP 5.4 | |
$arr = []; | |
$arr2 = ['a','b','c']; | |
$arr3 = ['a' => 2, 'b' => 4, 'c' => 8]; | |
$arr4 = [['abc','def'], [2,4,8], 16]]; |
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
Notice: Array to string conversion in [...] on line 8 |
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 | |
function makeArray() { | |
return [1,2,3]; | |
} | |
// The PHP 5.3 way | |
$arr = makeArray(); | |
echo $arr[2]; | |
// The PHP 5.4 way | |
echo makeArray()[2]; // returns 3 |
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 | |
// PHP 5.3 | |
$f = new Foo(); | |
echo $f->bar(); | |
// PHP 5.4 | |
echo (new Foo)->bar(); |
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 | |
trait FooBar { | |
... | |
} | |
class Foo { | |
use FooBar; | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment