I am a newbie in PHP.
I have
$input = readline("\nEnter object:");
to read the name of the object that the user wants the details of, to variable $input
, which by default becomes a string.
I need to check if there exists an object named $input
, in any of the classes that i have defined, and call functions accordingly,like
$this->getObsDetails()
if it belongs to class Obstacles,
else
$this->getCharaDetails()
if it belongs to class Characters.
I cannot use is_object($input)
or get_class($input)
function as $input
is a string.
How can I efficiently achieve this?
Edit: I have a GameObjects class, which is the base class for Characters and Obstacles classes. I have a public function in GameObjects
public function printDetails() {
/*
based on the class of the calling object, which I intend to find
here itself using get_class($this), I intend to call respective functions as */
$this->getCharaDetails();
// OR
$this->getObsDetails();
}
Now, outside the class using is_object($$input)
I know if there exists an object named $input
. But $$input->printDetails()
or $input->printDetails()
cannot be performed.
How do I do it?