This is a discussion on PHP 4: does method_exist return true if parent class method even if child class forgot to call parent:: within the PHP Language forums, part of the PHP Programming Forums category; My code was dying on the line below where I use method_exists: if (class_exists($nameOfClassToBeUsed)) { $object = new $nameOfClassToBeUsed(); $this->...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
On 2005-05-28, lkrubner@geocities.com <lkrubner@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 |
|
|||
|
On 28 May 2005 07:03:45 -0700, lkrubner@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. |