3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class ObjectCreator { public static function create(string $className, array $properties) { $instance = (new ReflectionClass($className)) ->newInstanceWithoutConstructor(); $reflection = new ReflectionObject($instance); foreach ($properties as $field => $value) { $property = $reflection->getProperty($field); $property->setAccessible(true); $property->setValue($instance, $value); } return $instance; } } final class Orang { /** * @var string */ private $id; public function getId(): string { return $this->id; } /** * @var string */ private $nama; public function getNama(): string { return $this->nama; } public function __construct(string $id, string $nama) { $this->id = $id; $this->nama = $nama; } } $orang = ObjectCreator::create(Orang::class, [ 'id' => 'some_id', 'nama' => 'Some Name' ]); echo $orang->getId(), PHP_EOL; echo $orang->getNama(), PHP_EOL;
Output for git.master, git.master_jit, rfc.property-hooks
some_id Some Name

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