A void function must not return a value } function lacks_return(): void { // valid } function returns_nothing(): void { return; // valid } function returns_null(): void { return null; // Fatal error: A void function must not return a value } function foobar(void $foo) {} // Fatal error: void cannot be used as a parameter type
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; }
time error will be thrown // for anything else. // Mirroring the behavior of methods. interface ICache { public const PUBLIC = 0; const IMPLICIT_PUBLIC = 1; }
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 = []) { // ... }
$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}"; } }
$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}"; } }