I declared class which has 1 object . calling method with that object is okay , but calling methods which was not-an-object causing no output .. here it demonstrates
// defining simple class
class Person{
function say_hello($name='world')
{
echo "hello {$name}";
}
}
$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();
?>
I’m using PHP Version 5.2.17 in IIS Express in webmatrix platform .
$ob ist not a Person, so how should the interpreter know that you want access Person?
if you want to access the function without an object, try: