note 77230 added to language.oop5.basic
| From: | dulao5 at osu1 dot php dot net | Date: | Tue, 21 Aug 2007 03:13:10 +0000 |
| Subject: | note 77230 added to language.oop5.basic | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129657@lists.php.net to get a copy of this message | ||
$this is a reference to the calling object
(usually the object to which the method belongs,
but can be another object,
if the method is called statically from the context of a secondary object).
note:
æ³¨ææ¯âéæè°ç¨âèééææ¹æ³ã
ç»è¿æµè¯ï¼éææ¹æ³ç»å¯¹ä¸ä¼æthis伪åéã
#!/usr/local/bin/php
<?php
class ClassB{
const NAME = "Class B";
public $a = ClassB::NAME;
public function foo(){
//å½è¿ä¸ªæ¹æ³è¢«å¯¹è±¡$aéæè°ç¨æ¶ï¼this==$a
echo $this->a.":: foo call\n";
echo "'this' is a {$this->a} object\n";
}
};
class ClassA{
const NAME = "class A";
public $a = ClassA::NAME;
public function createB(){
return new ClassB();
}
public function foo(){
echo $this->a.":: foo call\n";
echo "\n\nCall a object function\n";
$this->createB()->foo();
echo "\n\nthe method is called statically from \$A\n";
ClassB::foo();
}
}
$A = new ClassA();
$A->foo();
?>
----
Server IP: 69.147.83.197
Probable Submitter: 222.128.39.136
----
Manual Page -- http://www.php.net/manual/en/language.oop5.basic.php
Edit -- https://master.php.net/note/edit/77230
Del: integrated -- https://master.php.net/note/delete/77230/integrated
Del: useless -- https://master.php.net/note/delete/77230/useless
Del: bad code -- https://master.php.net/note/delete/77230/bad+code
Del: spam -- https://master.php.net/note/delete/77230/spam
Del: non-english -- https://master.php.net/note/delete/77230/non-english
Del: in docs -- https://master.php.net/note/delete/77230/in+docs
Del: other reasons-- https://master.php.net/note/delete/77230
Reject -- https://master.php.net/note/reject/77230
Search -- https://master.php.net/manage/user-notes.php