Basis for Symfony 2, Zend Framework 2, Laravel 4...
$array = array('PHP', '5.3');
$array = ['PHP', '5.4+'];
echo array('PHP', '5.4+')[0];
function helloTF1() {
return ['Hello', 'TF1'];
}
echo helloTF1()[1];
echo 'Hugo'[1];
class A {
private $value = 1;
public function getClosure()
{
return function() {
return $this->value;
};
}
}
$a = new A;
$fn = $a->getClosure();
echo $fn(); // 1
Class member access on instantiation has been added, e.g. (new Foo)->bar().
Traits are a mechanism for code reuse in single inheritance languages such as PHP
trait Color {
public function getColor() {
return 'blue';
}
}
class Vehicle {}
class Car extends Vehicle {
use Color;
}
$myCar = new Car;
echo $myCar->getColor(); // blue
A new keyword, insteadof
, has been added to prevent conflicts in traits
Without it, if you get a conflict, fatal error.
Don't use them as a replacement for class inheritance (as seem to do 50% of the explanations on the Internet)
hugo@VF19:~> php -S localhost:8000
python -m SimpleHTTPServer 8000
Obviously, only for tests
htmlspecialchars
& htmlentities
's default character set changed from ISO-8859-1 to UTF-8
/e
flag in preg_replace
$a = '';
empty($a);
$b = ' ';
empty(trim($b));
array range (mixed $start , mixed $end)
function xrange($start, $limit) {
for ($i = $start; $i <= $limit; $i++) {
yield $i;
}
}
$data = range(0, 1000000);
echo memory_get_usage() / 1048576 . " MB";
// output: 137.92 MB
$data = range(0, 1000000);
echo memory_get_usage() / 1048576 . " MB";
// output: 0.22 MB
foreach ($data as $key => $val) {
echo "key: ".$key." value: ".$val."\n";
}
try {
//do something
} catch(Exception ex) {
//handle an error
} finally {
//clean up after yourself
}
class A {}
echo A::class;
$array = [[1, 2], [3, 4]];
foreach ($array as list($a, $b)) {
echo "First: $a; Second: $b\n";
}
Zend Optimizer+ as OPcache extension
New functions for secure password hashing
The Software shall be used for Good, not Evil.
We want to (be able to) be evil!
So the extension ext/JSON got replaced by a free one and there should* not exist any problems
No more 4 years gap between two versions
A yearly cycle has started in 2011
2 years with bug & security fixes, 1 year with only security fixes
Should be out in 2014
class MySQL implements DB {
public function query($query, ...$params) {
$stmt = $this->pdo->prepare($query);
$stmt->execute($params);
return $stmt;
}
// ...
}
function create_query(
$where, $order_by, $join_type='',
$execute = false, $report_errors = true
);
create_query(
"deleted=0", "name", default,
default, false);
Problems for the future : the (lack of) vision
The PHP internals are a battlefield
What major changes should PHP 6 bring?
Look at all the amazing stuff we build - The language can’t be that bad!
I don't believe it is :)