note 94331 added to function.get-called-class
| From: | AbhiBeckert at osu1 dot php dot net | Date: | Thu, 29 Oct 2009 04:41:34 +0000 |
| Subject: | note 94331 added to function.get-called-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162226@lists.php.net to get a copy of this message | ||
Beware that this does not behave as expected if your method is not declared as static! For example:
<?php
class foo {
static public function test() {
var_dump(get_called_class());
}
public function testTwo() {
var_dump(get_called_class());
}
}
class bar extends foo {
}
class abc {
function test() {
foo::test();
bar::test();
}
function testTwo() {
foo::testTwo();
bar::testTwo();
}
}
echo "basic\n";
foo::test();
bar::test();
echo "basic without static declaration\n";
foo::testTwo();
bar::testTwo();
echo "in a class\n";
$abc = new abc();
$abc->test();
echo "in a class without static declaration\n";
$abc->testTwo();
?>
The result is:
basic
string 'foo'
string 'bar'
basic without static declaration
string 'foo'
string 'bar'
in a class
string 'foo'
string 'bar'
in a class without static declaration
string 'abc'
string 'abc'
----
Server IP: 117.104.162.229
Probable Submitter: 150.101.184.93 (proxied: 150.101.184.93)
----
Manual Page -- http://www.php.net/manual/en/function.get-called-class.php
Edit -- https://master.php.net/note/edit/94331
Del: integrated -- https://master.php.net/note/delete/94331/integrated
Del: useless -- https://master.php.net/note/delete/94331/useless
Del: bad code -- https://master.php.net/note/delete/94331/bad+code
Del: spam -- https://master.php.net/note/delete/94331/spam
Del: non-english -- https://master.php.net/note/delete/94331/non-english
Del: in docs -- https://master.php.net/note/delete/94331/in+docs
Del: other reasons-- https://master.php.net/note/delete/94331
Reject -- https://master.php.net/note/reject/94331
Search -- https://master.php.net/manage/user-notes.php