3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Car { protected array $tags; public function __get(string $prop): mixed { print("__get($prop) called"); if (property_exists($this, $prop)) { return $this->{$prop}; } } public function __set(string $prop, mixed $val): void { if (property_exists($this, $prop)) { $this->$prop = $val; } } } class CarMapper { public function test(Car $car): void { echo 'そのままだとtrueになる'.PHP_EOL; var_dump(empty($car->tags)); // bool(true) echo '代入するとfalseになる'.PHP_EOL; $tags = $car->tags; var_dump(empty($tags)); // bool(false) } } $car = new Car(); $car->tags = ['tag1']; $carMapper = new CarMapper(); $carMapper->test($car);
Output for git.master_jit, git.master, rfc.property-hooks
そのままだとtrueになる bool(true) 代入するとfalseになる __get(tags) calledbool(false)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
38.97 ms | 405 KiB | 5 Q