3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class IAmImmutable { private $name; public static function createFromName($name) { return new self($name); } private function __construct($name) { $this->name = $name; } public function getName() { return $this->name; } } $object = IAmImmutable::createFromName('Peter'); var_dump($object instanceof IAmImmutable); var_dump($object->getName()); $object->__construct('Bob'); var_dump($object->getName());
based on RAURr
Output for 7.0.0 - 7.2.0
bool(true) string(5) "Peter" Fatal error: Uncaught Error: Call to private method IAmImmutable::__construct() from context '' in /in/naLrV:29 Stack trace: #0 {main} thrown in /in/naLrV on line 29
Process exited with code 255.
Output for 5.3.19 - 5.6.28
bool(true) string(5) "Peter" Fatal error: Call to private method IAmImmutable::__construct() from context '' in /in/naLrV on line 29
Process exited with code 255.