Probably I am missing something about the php workings but listen to this because it is working!
Let’s say we have three classes
<?php
class Grandparent {
public function myMethod($param) {
return 1;
}
}
class Parent extends Grandparent {
public function myMethod($param) {
return parent::myMethod($param) + 1;
}
}
class Son extents Parent {
public function myMethod($param) {
return parent::myMethod($param) + 1;
}
}
?>
Let’s assume that you do not want to change the Parent or the Grandparent class because it is the source code developed from somebody else and you only have authorization to create the Son class.
Let’s also assume that there is some functionality inside the parent class which is unwanted !!
Moreover you want all the functionality that there is inside the Grandparent class !!!
How do you skip to call the parent method ? Let me remind you that the chain parent::parent::myMethod() is invalid !
get_parent_class only returns a string. So after two calls what you have inside $grandparent variable is a string ‘Grandparent’.
My first thought was that if I just call Grandparent::myMethod I would get an error because myMethod is NOT a static method and therefore cannot be called statically.
Well this is NOT the case here since this call works perfectly!
The grandparent method is called and we have successfully skipped calling parent method!
mdomba I currently have php 5.3.6 and did you really not get that "Parent" was only for the explanation??
Of course you cannot define a class as parent, I named it this way merely for an example !! (obvious I believe)
I also have all errors on now in development, E_STRICT etc.
Yes that is what I am telling you. I do NOT get this error. This was not a question of mine. Did you even try my code to see for yourself that it works?
As you put the code in a code block… it’s expected to be working with copy/paste… even if you use class/variable names for explanation… that’s why I wrote you about the “parent” reserved word…
Of course I tested this (PHP 5.3.5)… where would I get the error I posted above?
Note that this error is shown only if you enable E_NOTICE… and that one is not included in E_ALL.