note 56117 added to function.get-class
| From: | winescout at yahoo dot com | Date: | Wed, 24 Aug 2005 03:37:42 +0000 |
| Subject: | note 56117 added to function.get-class | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94108@lists.php.net to get a copy of this message | ||
I believe this to be a bug, but its behavior is worth noting here. When calling the static function
of a parent class, get_class() returns the name of the parent, as does __CLASS__.
<?php
require_once 'PHPUnit2/Framework/TestCase.php';
class StaticInheritanceTest extends PHPUnit2_Framework_TestCase {
public function testClassVariable(){
$this->assertEquals("Child",Child::getClassVariableValue());
}
public function testClassMethodValue(){
$this->assertEquals("Child",Child::getClassMethodValue());
}
}
class Elder{
static function getClassVariableValue(){
return __CLASS__;
}
static function getClassMethodValue(){
return get_class();
}
}
class Child extends Elder{
}
?>
Here is the result --
There were 2 failures:
1) testClasVariable(StaticInheritanceTest)
expected: <Child> but was: <Elder>
2) testClassMethodValue(StaticInheritanceTest)
expected: <Child> but was: <Elder>
FAILURES!!!
Tests run: 2, Failures: 2, Errors: 0, Incomplete Tests: 0.
----
Manual Page -- http://www.php.net/manual/en/function.get-class.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56117
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56117&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56117&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56117&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56117&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56117&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56117&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56117&report=yes
Search -- http://master.php.net/manage/user-notes.php