3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Test { private static $data = []; public static function Set($key, $value) { static::$data[$key] = $value; } public static function Get($key) { return static::$data[$key]; } } class TestTrait { use Test; public function __construct(){} public function setArrayValues(array $array) { foreach ($array as $key => $value) { Test::Set($key, $value); } } public function getArrayValueFromKey(array $array) { foreach ($array as $key => $value) { var_dump(Test::Get($key)); } } } $songs = [ 'Burial' => 'God is an Astronaut', 'Hazard' => 'Long Distance Calling', 'An Infinite Regression' => 'Animals as Leaders', ]; $testTrait = new TestTrait(); $testTrait->setArrayValues($songs); $testTrait->getArrayValueFromKey($songs);
Output for git.master, git.master_jit, rfc.property-hooks
Deprecated: Calling static trait method Test::Set is deprecated, it should only be called on a class using the trait in /in/86J6R on line 23 Deprecated: Accessing static trait property Test::$data is deprecated, it should only be accessed on a class using the trait in /in/86J6R on line 7 Deprecated: Calling static trait method Test::Set is deprecated, it should only be called on a class using the trait in /in/86J6R on line 23 Deprecated: Accessing static trait property Test::$data is deprecated, it should only be accessed on a class using the trait in /in/86J6R on line 7 Deprecated: Calling static trait method Test::Set is deprecated, it should only be called on a class using the trait in /in/86J6R on line 23 Deprecated: Accessing static trait property Test::$data is deprecated, it should only be accessed on a class using the trait in /in/86J6R on line 7 Deprecated: Calling static trait method Test::Get is deprecated, it should only be called on a class using the trait in /in/86J6R on line 30 Deprecated: Accessing static trait property Test::$data is deprecated, it should only be accessed on a class using the trait in /in/86J6R on line 10 string(19) "God is an Astronaut" Deprecated: Calling static trait method Test::Get is deprecated, it should only be called on a class using the trait in /in/86J6R on line 30 Deprecated: Accessing static trait property Test::$data is deprecated, it should only be accessed on a class using the trait in /in/86J6R on line 10 string(21) "Long Distance Calling" Deprecated: Calling static trait method Test::Get is deprecated, it should only be called on a class using the trait in /in/86J6R on line 30 Deprecated: Accessing static trait property Test::$data is deprecated, it should only be accessed on a class using the trait in /in/86J6R on line 10 string(18) "Animals as Leaders"

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:
18.47 ms | 405 KiB | 8 Q