note 81437 deleted from language.oop5.basic by felipe
| From: | felipe@php.net | Date: | Mon, 24 Mar 2008 22:15:59 +0000 |
| Subject: | note 81437 deleted from language.oop5.basic by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-137481@lists.php.net to get a copy of this message | ||
Note Submitter: msaspence at gmail dot com
----
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.