szymanskilukasz Łukasz Szymański Development Team Lead at @szymanskilukasz https://www.linkedin.com/in/szymanskilukasz https://twitter.com/szymanskilukasz https://speakerdeck.com/szymanskilukasz
szymanskilukasz class Token { // Constants default to public const PUBLIC_CONST = 0;
// Constants then also can have a defined visibility private const PRIVATE_CONST = 0; protected const PROTECTED_CONST = 0; public const PUBLIC_CONST_TWO = 0;
//Constants can only have one visibility declaration list private const FOO = 1, BAR = 2; }
szymanskilukasz //Interfaces only support public consts, // and a compile time error will be thrown // for anything else. // Mirroring the behavior of methods.
interface ICache { public const PUBLIC = 0; const IMPLICIT_PUBLIC = 1; }
szymanskilukasz // nullability can be removed by a subclass interface Fooable { function foo(): ?Fooable; } interface StrictFooable extends Fooable { function foo(): Fooable; // valid }
szymanskilukasz // but it cannot be added interface Fooable { function foo(): Fooable; } interface LooseFooable extends Fooable { function foo(): ?Fooable; // invalid }
szymanskilukasz // If a value is not an array or instance of Traversable, // a TypeError will be thrown. function foo(iterable $iterable) { foreach ($iterable as $value) { // ... } }
// If the returned value is not an array // or instance of Traversable, a TypeError will be thrown. function bar(): iterable { return [1, 2, 3]; }
// Parameters declared as iterable // may use null or an array as a default value function foo(iterable $iterable = []) { // ... }
szymanskilukasz class HumanResourceReport { private $person;
public function __construct(Person $person) { $this->person = $person; }
public function getFullName() { // HumanResourceReport would not have access to protected // members of Person if not explicitly listed as a friend. return $this->person->firstName . ' ' . $this->person->lastName; }
public function getReportIdentifier() { return "HR_REPORT_ID_{$this->person->id}"; } }
szymanskilukasz class HumanResourceReport { private $person;
public function __construct(Person $person) { $this->person = $person; }
public function getFullName() { // HumanResourceReport would not have access to protected // members of Person if not explicitly listed as a friend. return $this->person->firstName . ' ' . $this->person->lastName; }
public function getReportIdentifier() { return "HR_REPORT_ID_{$this->person->id}"; } }
szymanskilukasz // Using positional arguments: array_fill(0, 100, 42); // Using named arguments: array_fill(start_index => 0, num => 100, value => 42);
szymanskilukasz Łukasz Szymański Development Team Lead at @szymanskilukasz https://www.linkedin.com/in/szymanskilukasz https://twitter.com/szymanskilukasz https://speakerdeck.com/szymanskilukasz