3v4l.org

run code in 300+ PHP versions simultaneously
<?php class User { const HARDCODED_NAME = 'Васян'; public $fullName = [ 'surname' => 'Иванов', 'name' => 'Иван', 'patronymic' => 'Иванович', ]; } $property = 'fullName'; $user = new User; echo $user->$property['surname'] . PHP_EOL; // Выведет "Иванов" class Child extends User { public $parent; public $fullName = [ 'surname' => 'Петров', 'name' => 'Петр', 'patronymic' => 'Петрович', ]; public function __construct(User $parent) { $this->parent = $parent; } } $parentProperty = 'parent'; $child = new Child(new User); echo $user->$property['surname'] . PHP_EOL; // Выведет "Петров" echo $child->$parentProperty::HARDCODED_NAME . PHP_EOL; // Выведет "Васян" $arrayProperty = ['parent']; echo $child->{$arrayProperty[0]}::HARDCODED_NAME . PHP_EOL; // Выведет "Васян"
Output for git.master, git.master_jit, rfc.property-hooks
Иванов Иванов Васян Васян

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