3v4l.org

run code in 300+ PHP versions simultaneously
<?php class SomeImmutableObject { private $someString; private $flagCreate = false; public function __construct(string $value) { if ($this->flagCreate === true) { throw new \BadMethodCallException('This immutable object has already been created.'); } $this->someString = $value; $this->flagCreate = true; } public function getValue(): string { return 'the value is:' . $this->someString . ' - '; } } class AnotherClassToBreakImmutableObject extends SomeImmutableObject { public function __construct(string $value) { $this->someString = $value; } public function getValue(): string { return 'the value is:' . $this->someString . ' - '; } public function change(): void { $this->someString .= ' and Baz'; } } $three = new AnotherClassToBreakImmutableObject('Foo'); echo $three->getValue(); //Foo echo $three->change(); echo $three->getValue(); //the value is: Foo and Baz -
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property AnotherClassToBreakImmutableObject::$someString is deprecated in /in/JmkoK on line 29 the value is:Foo - the value is:Foo and Baz -

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:
28.77 ms | 405 KiB | 5 Q