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 is an immutable object has already create.'); } $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 Minny'; } } $three = new AnotherClassToBreakImmutableObject('Pippo'); echo $three->getValue(); //Pippo echo $three->change(); echo $three->getValue(); //the value is: Pippo and Minny -
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Creation of dynamic property AnotherClassToBreakImmutableObject::$someString is deprecated in /in/KpnfR on line 29 the value is:Pippo - the value is:Pippo and Minny -

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:
59.42 ms | 401 KiB | 8 Q