我声明了有1个对象的类。使用该对象调用方法是可以的,但调用非对象的方法不会导致输出..这里演示
// defining simple class class Person{ function say_hello($name='world') { echo "hello {$name}";我在webmatrix平台的IIS Express中使用PHP版本5.2.17。} } $instant1 = new Person(); $object2 = new Person(); echo get_class($object2); ?> <br/> <?php if(is_a($object2,'Person')) { //remeber to pass arguments echo "This object or instant is in that class"; } else { echo "No dude :( "; } ?> <?php $instant1->say_hello('Paritosh'); echo " <br/>";
$ob->say_hello(); // No error No output , even there is no object with name $ob and below code is not running // is it bug or any concept ?
echo "No output ";
$object2->say_hello();?>
答案 0 :(得分:0)
$ ob不是Person,那么解释器应该如何知道你想要访问Person? 如果要在没有对象的情况下访问该函数,请尝试:
Person::say_hello();