3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Msg { var $x = array(); function __construct() { echo "CONSTRUCTOR CALLED\r\n"; } function testStaticSet() { Msg::setValue("ERROR", 'HELLO!'); } function setValue($name, $value) { if(!isset($this)) { echo "called static outside of class!\n"; return false; } $this->x[$name] = $value; } function getValue($name) { if(!isset($this)) { echo "called static outside of class!\n"; return false; } return $this->x[$name]; } } Msg::setValue("ERROR", 'Hello World!'); echo Msg::getValue("ERROR"); $a = new Msg(); $a->testStaticSet(); echo $a->getValue("ERROR");
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Non-static method Msg::setValue() cannot be called statically in /in/YsJdX:30 Stack trace: #0 {main} thrown in /in/YsJdX on line 30
Process exited with code 255.
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: Non-static method Msg::setValue() should not be called statically in /in/YsJdX on line 30 called static outside of class! Deprecated: Non-static method Msg::getValue() should not be called statically in /in/YsJdX on line 31 called static outside of class! CONSTRUCTOR CALLED HELLO!
Output for 7.3.32 - 7.3.33
called static outside of class! called static outside of class! CONSTRUCTOR CALLED HELLO!
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Strict Standards: Non-static method Msg::setValue() should not be called statically in /in/YsJdX on line 30 called static outside of class! Strict Standards: Non-static method Msg::getValue() should not be called statically in /in/YsJdX on line 31 called static outside of class! CONSTRUCTOR CALLED HELLO!

preferences:
166.08 ms | 402 KiB | 198 Q