note 83854 deleted from language.oop5 by tularis
| From: | tularis@php.net | Date: | Sun, 15 Jun 2008 14:41:51 +0000 |
| Subject: | note 83854 deleted from language.oop5 by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-140477@lists.php.net to get a copy of this message | ||
Note Submitter: isapoetra at gmail dot com
----
Warning!!! using self, self in php mean about class in where you put self expression not child or
child of child .....
abstract class cparent {
public static function callme() {
echo "from ".__CLASS__." ".__FUNCTION__."\n";
}
public static function callme2() {
echo "from ".__CLASS__." ".__FUNCTION__."\n";
return false;
}
public static function errorself() {
if (self::callme2()){
echo "from ".__CLASS__." ".__FUNCTION__."\n";
}
}
}
abstract class child1 extends cparent {
public static function callme2() {
//this function not called by parent. whyyyyyyy?
echo "from ".__CLASS__." ".__FUNCTION__."\n";
return true;
}
public static function callme() {
echo "from ".__CLASS__." ".__FUNCTION__."\n";
}
}
final class child2 extends child1 {
public static function callme2() {
//this function not called by parent. whyyyyyyy?
echo "from ".__CLASS__." ".__FUNCTION__."\n";
return true;
}
public static function callme() {
if (self::callme2()) {
echo "from ".__CLASS__." ".__FUNCTION__."\n";
}
}
}
//worked
call_user_func(array("child2","callme"));
//callme2 in class child2 not called
call_user_func(array("child2","errorself"));
solution
final class child3 extends child1 {
public static function errorself() {
if (self::callme2()){
echo "from ".__CLASS__." ".__FUNCTION__."\n";
}
}
}