By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,409 Members | 1,524 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,409 IT Pros & Developers. It's quick & easy.

PHP 4: does method_exist return true if parent class method even if child class forgot to call parent::

P: n/a
My code was dying on the line below where I use method_exists:

if (class_exists($nameOfClassToBeUsed)) {
$object = new $nameOfClassToBeUsed();
$this->arrayOfAllTheObjectsSoFarLoaded[$nameOfClassToBeUsed] = &
$object;
if (method_exists($object, "setCallingCode"))
$object->setCallingCode($nameOfFunctionOrClassCalling);
return $object;
} else {
$this->error("$nameOfClassToBeUsed not found. The code that wants
this class is $nameOfFunctionOrClassCalling ");
}

The method is in the parent class yet I'd forgotten to call parent:: in
the constructor of the child class. It seems to me that method_exists
was testing true, though the method was not truly available, and then
the code died. Adding parent:: to the constructor of the child solved
the problem. Is this a bug in PHP?

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 2005-05-28, lk******@geocities.com <lk******@geocities.com> wrote:
The method is in the parent class yet I'd forgotten to call parent::
in the constructor of the child class. It seems to me that
method_exists was testing true, though the method was not truly
available, and then the code died. Adding parent:: to the constructor
of the child solved the problem. Is this a bug in PHP?


You shouldn't have to call the parent class to get access to its
methods. If class B extends class A then all methods of class A is
available in class B.

--
Cheers,
- Jacob Atzen
Jul 17 '05 #2

P: n/a
On 28 May 2005 07:03:45 -0700, lk******@geocities.com wrote:
Adding parent:: to the constructor of the child solved
the problem. Is this a bug in PHP?
Nope.
The method is in the parent class yet I'd forgotten to call parent:: in
the constructor of the child class.


That's correct behaviour. Calling the parents constructor has nothing
to do with whether the methods are available in a child class.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.