<?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);
You have javascript disabled. You will not be able to edit any code.