Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.
For the best experience please use the latest Chrome, Safari or Firefox browser.
2012: Research PHP+JIT begins, led by Dmitry Stogov
2014: No performance gains realized for real-world workloads
(% improvement vs. PHP 5.6)
$foo->bar()();
$foo
is an objectbar()
is a method that returns a callable$foo()[‘bar’]();
$foo
is a method that returns an array.['bar']
is an element in the array returned by $foo()
['bar']
contains a callable as it’s value()
calls the callable contained in ['bar']
function getStr()
{
return 'Jan Burkl';
}
echo getStr(){4}; // 'B'
Double $ in referencing globals are no longer supported.
global $$foo->bar;
//No longer supported
There are no longer any restrictions on nesting of dereferencing operations. All of these are now supported:
$obj1 = new StdClass();
$obj1->name = 'Barbara';
$obj2 = new StdClass();
$obj2->name = 'Jan';
$returnVal = [$obj1, $obj2][0]->name;
Reference a property statically from a class reference
$foo['bar']::$baz
Statically access a nested referenced property
$foo::$bar::$baz
Call a referenced method statically from a class reference returned by a method.
$foo->bar()::baz()
Old Meaning | New Meaning | |
---|---|---|
$$foo['bar']['baz'] |
${$foo['bar']['baz']} |
($$foo)['bar']['baz'] |
$foo->$bar['baz'] |
$foo->{$bar['baz']} |
($foo->$bar)['baz'] |
$foo->$bar['baz']() |
$foo->{$bar['baz']}() |
($foo->$bar)['baz']() |
Foo::$bar['baz']() |
Foo::{$bar['baz']}() |
(Foo::$bar)['baz']() |
echo 1<=>2; // -1
echo 1<=>1; // 0
echo 2<=>1; // 1
echo [] <=> []; // 0
echo [1, 2, 3] <=> [1, 2, 3]; // 0
echo [1, 2, 3] <=> []; // 1
echo [1, 2, 3] <=> [1, 2, 1]; // 1
echo [1, 2, 3] <=> [1, 2, 4]; // -1
$a = (object) ["a" => "b"];
$b = (object) ["a" => "c"];
echo $a <=> $b; // -1
$a = (object) ["a" => "b"];
$b = (object) ["a" => "b"];
echo $a <=> $b; // 0
$array = ['oranges', 'apples',
'bananas', 'grapes'];
usort($array,
function ($left,$right) {
return $left<=>$right;
}
);
Array (
[0] => apples
[1] => bananas
[2] => grapes
[3] => oranges
)
$obj = new class($i) {
public function __construct($i) {
$this->i = $i;
};
}
(new class extends ConsoleProgram {
public function main() {
/* ... */
}
})->bootstrap();
return new class($controller)
implements Page {
public function
__construct($controller) {
/* ... */
}
/* ... */
};
$pusher->setLogger(new class {
public function log($msg) {
print_r($msg . "\n");
}
});
function foo() {
$returnValue = 1;
yield 1;
$returnValue = 2;
yield 2;
return $returnValue;
}
$bar = foo();
foreach ($bar as $element) {
echo $element, "\n";
}
var_dump($bar->getReturn());
// 1
// 2
// int(2)
function foo() {
yield 1;
yield 2;
}
function both() {
yield from foo();
yield from [2, 3, 4];
yield "done"
}
$a = both();
foreach ($a as $value) {
echo $value . "\n";
}
// this will unserialize everything
// as before
$data = unserialize($foo);
// this will convert all objects into
// __PHP_Incomplete_Class object
$data = unserialize(
$foo,
["allowed_classes" => false]
);
// converts all objects except MyClass
// into __PHP_Incomplete_Class object
$data = unserialize(
$foo,
["allowed_classes" => [
"MyClass"
]);
//accept all classes as in default
$data = unserialize(
$foo,
["allowed_classes" => true]
);
try {
do_something(null); // oops!
} catch (\Error $e) {
echo "Err: {$e->getMessage()}\n";
}
// Error: Call to a member function
// method() on a non-object
function add(int $left, int $right) {
return $left + $right;
}
try {
echo add('left', 'right');
} catch (\TypeError $e) {
// Log error and end gracefully
} catch (\Exception $e) {
// Handle any exceptions
} catch (\Throwable $e) {
// Handle everything else
}
$code = 'var_dup($admin);';
try {
$result = eval($code);
} catch (\ParseError $error) {
// Handle $error
}
if ($admin) {
try {
include "./issue_code.php";
} catch (\ParseError $error) {
// Handle $error
}
}
$name = $firstName ?? "Jan";
$name .= " ";
$name .= $lastName ?? "Burkl";
$this->maxCount = is_null(
$input->getOption('count'))
? -1 : $input->getOption('count');
$this->maxCount =
$input->getOption('count') ?? -1;
$x = NULL;
$y = NULL;
$z = 3;
var_dump($x ?? $y ?? $z); // int(3)
function add(float $a, float $b) {
return $a + $b;
}
$returnValue = add(1.5, 2.5);
// int(4)
// Works
$returnValue = add("1 foo", "2");
// PHP 5.6 and below gives a Notice
// PHP7 TypeError
$returnValue = add(1, 2); // int(3)
// Widening
declare(strict_types=1);
function add(float $a, float $b) {
return $a + $b;
}
var_dump(add(1, 2)); // float(3)
function foo(): array {
return [];
}
class MyClass{
public function foo(): array {
return [];
}
}
class MyOtherClass extends MyClass {
public function foo(): MyClass {
return new MyClass();
}
}
class MyClass {
function make(): MyClass {
return new MyClass();
}
}
class MyOtherClass extends MyClass {
function make(): MyOtherClass {
return new MyOtherClass();
}
}
namespace MyProj\Command;
use MyProj\Traits\WritelineTrait;
use MyProj\Twitter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
namespace MyProj\Command;
use MyProj\ {
Traits\WritelineTrait,
Twitter
};
use Symfony\Component\Console\ {
Command\Command,
Input\InputOption,
Output\OutputInterface
};