Hello! According to rumors, on January 19, the next RC PHP 5.4 was to be released. It is even possible that it will be final. And this means that you need to quickly explore new opportunities.
For several years I have been professionally engaged in web development and use PHP as the main server language. So having learned about the release of such a major update, I went to collect information. Under the short list of the most significant innovations.
')
Impurities
Key novelty 5.4 - impurities. They will serve as a replacement for multi-inheritance in PHP. Each impurity is defined by a separate "class" through the keyword trait. Inside the impurity, methods can be defined that will become available in the class to which the impurities will be connected. Connection of impurities occurs through the use of language construction. The names of impurities are comma-separated and all their methods are available within the class.
If the names of the class methods and impurities match, then the priority method will be the class method. Unfortunately, in this case we will not get even Notice.
An impurity always has access to the class to which it is connected through the parent construct.
class A {
public function foo() {
return 'foo';
}
}
trait B {
public function bar() {
return parent::foo() . ' bar';
}
}
class C extends A {
use B;
}
$c = new C();
echo $c->foo(); // foo
echo $c->bar(); // foo bar
-. , multibyte . .
Array dereferencing support
— PHP . , ? , , ? :
function foo() {
return array(1, 2, 3);
}
echo foo()[0]; // 1
Short syntax for arrays
PHP 5.4 , array.
// :
$array = array(1, 2, 3);
// :
$array = [1, 2, 3];
// :
$array = ['first' => 1, 'second' => 2];
-
, PHP -, . - :
php -S localhost:8000
Upload progress
, HTML 5 File API ( ), PHP 5.4 . , ,
upload_progress_myform Ajax'
-.
, . , , .
class A {
public static function foo_bar() {
return '123';
}
}
$foo = 'foo';
$bar = 'bar';
echo A::{$foo . '_' . $bar}(); // 123
Scalar type hints
PHP . . : int, float boolean.
function foo(int $a, bool $b) {
return true;
}
@
@ PHP . @ - . .
- — . Exceptions.
Deleted
PHP - register_globals, long_arrays , .
Update: trail trait, ,
DoctorChaos .
Update 2: Scalar type hints PHP 5.4 .
,
SVN 5.4 scalar type hints :(
Irker sectus.