note 81437 added to language.oop5.basic
| From: | msaspence at gmail dot com | Date: | Thu, 28 Feb 2008 10:37:22 +0000 |
| Subject: | note 81437 added to language.oop5.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136551@lists.php.net to get a copy of this message | ||
In Example#1 get_class($this); returns the variable name of the object.
From what I can tell this is incorrect and it actually returns the class name of which the object is
an instance.
If should be:
<?php
class A
{
function foo()
{
if (isset($this)) {
echo '$this is defined (';
echo get_class($this);
echo ")\n";
} else {
echo "\$this is not defined.\n";
}
}
}
class B
{
function bar()
{
A::foo();
}
}
$a = new A();
$a->foo();
A::foo();
$b = new B();
$b->bar();
B::bar();
?>
Will out put:
$this is defined (A)
$this is not defined.
$this is defined (B)
$this is not defined.
A subtle but critical difference.
----
Server IP: 87.124.64.96
Probable Submitter: 129.12.38.134
----
Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php
Edit -- https://master.php.net/note/edit/81437
Del: integrated -- https://master.php.net/note/delete/81437/integrated
Del: useless -- https://master.php.net/note/delete/81437/useless
Del: bad code -- https://master.php.net/note/delete/81437/bad+code
Del: spam -- https://master.php.net/note/delete/81437/spam
Del: non-english -- https://master.php.net/note/delete/81437/non-english
Del: in docs -- https://master.php.net/note/delete/81437/in+docs
Del: other reasons-- https://master.php.net/note/delete/81437
Reject -- https://master.php.net/note/reject/81437
Search -- https://master.php.net/manage/user-notes.php