3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class Content { protected array $data = array('sequence'=>1); public function &__get(string $property) : mixed { if(isset($this->data[$property]) === false): $this->data[$property] = null; endif; return $this->data[$property]; } public function __set(string $name,mixed $value) : void { $this->data[$name] = $value; } } final class MyClass { private object $content; public function __construct(){ $this->content = new Content(); } public function generateSequence() : int { $result = $this->content->sequence * 2 + 1; $this->content->sequence += 1; return $result; } } $myclass = new MyClass(); print $myclass->generateSequence();
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.31, 8.2.0 - 8.2.26, 8.3.0 - 8.3.14, 8.4.1
3

preferences:
50.33 ms | 406 KiB | 5 Q