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 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
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"
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 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"
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30
string(19) "God is an Astronaut" string(21) "Long Distance Calling" string(18) "Animals as Leaders"

preferences:
142.92 ms | 402 KiB | 153 Q