3v4l.org

run code in 500+ PHP versions simultaneously
<?php class SomeClass { private $message = 'object message'; public static function someStaticMethod() { echo 'static call', PHP_EOL; } public function someObjectMethod() { echo 'object call', PHP_EOL; } public function getMessage() { echo $this->message, PHP_EOL; } private function test() { echo 'test'; } } $staticCallStaticMethod = array('SomeClass', 'someStaticMethod'); $staticCallObjectMethod = array('SomeClass', 'someObjectMethod'); $staticCallGetMessage = array('SomeClass', 'getMessage'); printf("SomeClass::someStaticMethod %s callable\n", is_callable($staticCallStaticMethod) ? "is" : "is not"); printf("SomeClass::someObjectMethod %s callable\n", is_callable($staticCallObjectMethod) ? "is" : "is not"); printf("SomeClass::getMessage %s callable\n", is_callable($staticCallGetMessage) ? "is" : "is not"); $object = new SomeClass(); $objectCallStaticMethod = array($object, 'someStaticMethod'); $objectCallObjectMethod = array($object, 'someObjectMethod'); $objectCallGetMessage = array($object, 'getMessage'); printf("\$object->someStaticMethod %s callable\n", is_callable($objectCallStaticMethod) ? "is" : "is not"); printf("\$object->someObjectMethod %s callable\n", is_callable($objectCallObjectMethod) ? "is" : "is not"); printf("\$object->getMessage %s callable\n", is_callable($objectCallGetMessage) ? "is" : "is not"); echo "Calling SomeClass::someObjectMethod:\n"; call_user_func($staticCallObjectMethod); echo "Calling \$object->someStaticMethod:\n"; call_user_func($objectCallStaticMethod); echo "Calling SomeClass::getMessage:\n"; call_user_func($staticCallGetMessage);
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
SomeClass::someStaticMethod is callable SomeClass::someObjectMethod is callable SomeClass::getMessage is callable $object->someStaticMethod is callable $object->someObjectMethod is callable $object->getMessage is callable Calling SomeClass::someObjectMethod: Deprecated: Non-static method SomeClass::someObjectMethod() should not be called statically in /in/2P3dd on line 46 object call Calling $object->someStaticMethod: static call Calling SomeClass::getMessage: Deprecated: Non-static method SomeClass::getMessage() should not be called statically in /in/2P3dd on line 52 Fatal error: Uncaught Error: Using $this when not in object context in /in/2P3dd:19 Stack trace: #0 /in/2P3dd(52): SomeClass::getMessage() #1 {main} thrown in /in/2P3dd on line 19
Process exited with code 255.
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.28
SomeClass::someStaticMethod is callable SomeClass::someObjectMethod is callable SomeClass::getMessage is callable $object->someStaticMethod is callable $object->someObjectMethod is callable $object->getMessage is callable Calling SomeClass::someObjectMethod: Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method SomeClass::someObjectMethod() should not be called statically in /in/2P3dd on line 46 object call Calling $object->someStaticMethod: static call Calling SomeClass::getMessage: Strict Standards: call_user_func() expects parameter 1 to be a valid callback, non-static method SomeClass::getMessage() should not be called statically in /in/2P3dd on line 52 Fatal error: Using $this when not in object context in /in/2P3dd on line 19
Process exited with code 255.
Output for 8.0.0 - 8.0.9
SomeClass::someStaticMethod is callable SomeClass::someObjectMethod is not callable SomeClass::getMessage is not callable $object->someStaticMethod is callable $object->someObjectMethod is callable $object->getMessage is callable Calling SomeClass::someObjectMethod: Fatal error: Uncaught TypeError: call_user_func(): Argument #1 ($function) must be a valid callback, non-static method SomeClass::someObjectMethod() cannot be called statically in /in/2P3dd:46 Stack trace: #0 {main} thrown in /in/2P3dd on line 46
Process exited with code 255.
Output for 8.0.10 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.34, 8.3.0 - 8.3.35, 8.4.1 - 8.4.26, 8.5.0 - 8.5.11
SomeClass::someStaticMethod is callable SomeClass::someObjectMethod is not callable SomeClass::getMessage is not callable $object->someStaticMethod is callable $object->someObjectMethod is callable $object->getMessage is callable Calling SomeClass::someObjectMethod: Fatal error: Uncaught TypeError: call_user_func(): Argument #1 ($callback) must be a valid callback, non-static method SomeClass::someObjectMethod() cannot be called statically in /in/2P3dd:46 Stack trace: #0 {main} thrown in /in/2P3dd on line 46
Process exited with code 255.
Output for 7.3.32 - 7.3.33
SomeClass::someStaticMethod is callable SomeClass::someObjectMethod is callable SomeClass::getMessage is callable $object->someStaticMethod is callable $object->someObjectMethod is callable $object->getMessage is callable Calling SomeClass::someObjectMethod: object call Calling $object->someStaticMethod: static call Calling SomeClass::getMessage: Fatal error: Uncaught Error: Using $this when not in object context in /in/2P3dd:19 Stack trace: #0 /in/2P3dd(52): SomeClass::getMessage() #1 {main} thrown in /in/2P3dd on line 19
Process exited with code 255.

preferences:
37.89 ms | 1157 KiB | 17 Q