note 49541 deleted from language.oop5.paamayim-nekudotayim by sobak
| From: | sobak@php.net | Date: | Thu, 01 Dec 2016 05:56:06 +0000 |
| Subject: | note 49541 deleted from language.oop5.paamayim-nekudotayim by sobak | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-207787@lists.php.net to get a copy of this message | ||
Note Submitter: ian at [first name]henderson dot org
----
Please note that methods called by the scope resolution operator which are defined by a superclass
of the first operand are called in the scope of the SUPERCLASS. For example,
<?php
class ExampleSuperclass
{
static function classType()
{
return "superclass";
}
static function doSomething()
{
echo "doing something with " . self::classType();
}
}
class ExampleClass extends ExampleSuperclass
{
static function classType()
{
return "subclass";
}
}
ExampleClass::doSomething();
// output is "doing something with superclass"!
?>
This can be surprising (it surprised me!) when coming from other object-oriented languages, which
would output "doing something with subclass" in this case.