note 97573 added to language.oop5.basic
| From: | ben dot corne at gmail dot com | Date: | Mon, 26 Apr 2010 19:35:10 +0000 |
| Subject: | note 97573 added to language.oop5.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168676@lists.php.net to get a copy of this message | ||
method calling context aware. By this I mean it will get treated differently while being in a new
statement compared to being in a regular call.
Example:
<?php
class Foo {
private $className = 'Bar';
public function make() {
return new $this->className();
}
public function callClassName() {
$this->className();
}
public function className() {
echo "foo\n";
}
};
class Bar {
public function hello() {
echo "bar\n";
}
};
$foo = new Foo();
$bar = $foo->make();
echo "expecting 'bar': ";
$bar->hello();
echo "expecting 'foo': ";
$foo->callClassName();
?>
even tough $this->className() is written two times in exactly the same way, the one contained in
a new statement gets the className field and the other performs the actual method.
----
Server IP: 69.147.83.197
Probable Submitter: 78.20.140.3
----
Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php
Edit -- https://master.php.net/note/edit/97573
Del: integrated -- https://master.php.net/note/delete/97573/integrated
Del: useless -- https://master.php.net/note/delete/97573/useless
Del: bad code -- https://master.php.net/note/delete/97573/bad+code
Del: spam -- https://master.php.net/note/delete/97573/spam
Del: non-english -- https://master.php.net/note/delete/97573/non-english
Del: in docs -- https://master.php.net/note/delete/97573/in+docs
Del: other reasons-- https://master.php.net/note/delete/97573
Reject -- https://master.php.net/note/reject/97573
Search -- https://master.php.net/manage/user-notes.php