3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php final class Immutable { private $somePropertyThatShouldntBeChanged; public static function create($value) { return new self($value); } private function __construct($value) { $this->somePropertyThatShouldntBeChanged = $value; } public function getValue() { return $this->somePropertyThatShouldntBeChanged; } } $foo = Immutable::create('immutable value'); echo $foo->getValue() . PHP_EOL; $foo->__construct('not immutable value'); echo $foo->getValue() . PHP_EOL;
based on 0BuZUQ
Output for 7.0.0 - 7.2.0
immutable value Fatal error: Uncaught Error: Call to private method Immutable::__construct() from context '' in /in/oOuEk:26 Stack trace: #0 {main} thrown in /in/oOuEk on line 26
Process exited with code 255.
Output for hhvm-3.12.14 - 3.17.3
immutable value Fatal error: Uncaught Error: Call to private Immutable::__construct() from invalid context in /in/oOuEk:26 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.30
immutable value Fatal error: Call to private method Immutable::__construct() from context '' in /in/oOuEk on line 26
Process exited with code 255.