PHP Göteborg, first meetup, 2015-05-27
Rickard Bennison
echo 1 <=> 1; // 0
echo 1 <=> 2; // -1
echo 2 <=> 1; // 1
$username = $_GET['user'] ?? 'nobody';
$username = isset($_GET['user']) ? $_GET['user'] : 'nobody';
use FooLibrary\Bar\Baz\{ ClassA, ClassB, ClassC, ClassD as Fizbo };
use FooLibrary\Bar\Baz\ClassA;
use FooLibrary\Bar\Baz\ClassB;
use FooLibrary\Bar\Baz\ClassC;
use FooLibrary\Bar\Baz\ClassD as Fizbo;
function call_method($obj) {
$obj->method();
}
call_method(null);
// Fatal error: Call to a member function method() on a non-object
try {
call_method(null); // oops!
} catch (EngineException $e) {
echo "Exception: {$e->getMessage()}\n";
}
// Exception: Call to a member function method() on a non-object
$pusher->setLogger(new class {
public function log($msg) {
print_r($msg . "\n");
}
});
class Foo { private $x = 3; }
$foo = new Foo;
$foobar = function () { var_dump($this->x); };
$foobar->call($foo); // prints int(3)
$bound = $foobar->bindTo($foo, $foo);
$bound(); // prints int(3)
Reduced memory consumption
Redured memory management overhead
Researched JIT compilation
Extensions need to be updated to support phpng
int
, float
, string
and bool
can now be typehinted
<?php
function add(float $a, float $b): float {
return $a + $b;
}
add("1", "2"); // float(3)
<?php
declare(strict_types=1);
function add(float $a, float $b): float {
return $a + $b;
}
add("1", "2");
// Catchable fatal error: Argument 1 passed to add() must be of the type integer
function foo(): array {
return [];
}
Comparable performance
Some similar features
Much smaller step/change
"Uniform Variable Syntax"
All deprecated functionality removed
First release candidate (RC) appearing in mid June.
Scheduled release Mid October 2015