This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| interface A | |
| { | |
| public function test(array $input); | |
| } | |
| class B implements A | |
| { | |
| public function test($input){} // type omitted for $input | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| use Foo\Bar\{ | |
| Foo, | |
| Bar, | |
| Baz, | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function test(?string $name) | |
| { | |
| var_dump($name); | |
| } | |
| test('elePHPant'); | |
| test(null); | |
| test(); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function swap(&$left, &$right): void | |
| { | |
| if ($left === $right) { | |
| return; | |
| } | |
| $tmp = $left; | |
| $left = $right; | |
| $right = $tmp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $data = [ | |
| [1, 'Tom'], | |
| [2, 'Fred'], | |
| ]; | |
| // list() style | |
| list($id1, $name1) = $data[0]; | |
| // [] style |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class ConstDemo | |
| { | |
| const PUBLIC_CONST_A = 1; | |
| public const PUBLIC_CONST_B = 2; | |
| protected const PROTECTED_CONST = 3; | |
| private const PRIVATE_CONST = 4; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function iterator(iterable $iter) | |
| { | |
| foreach ($iter as $val) { | |
| // | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| try { | |
| // some code | |
| } catch (FirstException | SecondException $e) { | |
| // handle first and second exceptions | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $data = [ | |
| ["id" => 1, "name" => 'Tom'], | |
| ["id" => 2, "name" => 'Fred'], | |
| ]; | |
| // list() style | |
| list("id" => $id1, "name" => $name1) = $data[0]; | |
| // [] style |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| var_dump("abcdef"[-2]); // string (1) "e" | |
| var_dump(strpos("aabbcc", "b", -3)); // int(3) | |
| /* | |
| * Negative string and array offsets are now also supported in | |
| * the simple variable parsing syntax inside of strings. | |
| */ | |
| $string = 'bar'; | |
| echo "The last char of '$string' is '$string[-1]'"; |