note 41016 deleted from language.oop by irchtml
| From: | irchtml@php.net | Date: | Sun, 18 Apr 2004 06:22:00 +0000 |
| Subject: | note 41016 deleted from language.oop by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-68281@lists.php.net to get a copy of this message | ||
Note Submitter: The Anarcat
----
(bugs.php.net is down so I can't figure out if this has already been filed)
"Instead, in order to be able to access it's own functions and variables from within a
class, one can use the pseudo-variable $this which can be read as 'my own' or
'current object'."
This makes me wonder if what I think is a bug really is a bug.
<?
class Father {
function name() {
return "Class : " . get_class($this);
}
}
class Brother extends Father {
function name() {
if (isset($this)) {
return parent::name();
} else {
print "static call<br>";
$p = new Brother();
return $p->name();
}
}
}
class Sister {
function static_brother_name() {
// workaround
// if (isset($this)) {
// unset($this);
// }
return Brother::name();
}
function nonstatic_brother_name() {
$bro = new Brother();
return $bro->name();
}
}
echo "Should be like this (non-static call in Sister::name()): <br>";
$p = new Sister(); echo "* " .$p->nonstatic_brother_name() . "<br>";
echo "* " .Sister::nonstatic_brother_name() . "<br>";
echo "Static call output this: <br>";
$p = new Sister(); echo "* " .$p->static_brother_name() . "<br>"; //
the problem is here
echo "* " .Sister::static_brother_name() . "<br>";
?>