PHP: This and Self
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
PHP: self vs this and
When to use self over $this
例子:
1 2 3 4 5 6 7 8 9 10 | class Object{ public $property; function doSomething(){ // This $something = $this->property; // Self $something = self::property; ...code... } } |
1 2 3 4 5 6 7 8 | class A { public static $staticVar = 'abc'; public $var = 'xyz'; public function doSomething () { echo self::$staticVar; echo $this->var; } } |
您的"自我"示例无论如何无效。
从这里夺走
链接:http://www.phpbuilder.com/board/showthread.php?t=10354489:
Use $this to refer to the current
object. Use self to refer to the
current class. In other words, use
$this->member for non-static members,
use self::$member for static members.
约翰·米利金在这里回答