note 41016 added to language.oop
| From: | TheAnarcat at rn2 dot php dot net | Date: | Fri, 26 Mar 2004 21:09:50 +0000 |
| Subject: | note 41016 added to language.oop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-67207@lists.php.net to get a copy of this message | ||
(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>";
?>
----
Manual Page -- http://www.php.net/manual/en/language.oop.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41016
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41016&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41016&report=yes
Search -- http://master.php.net/manage/user-notes.php