color 色的,有 $this->wheel_size 个轮子的车,我正在拉 $something "; }}$qiche = new Car();$qiche->color = '黑';$qiche->wheel_size = 12;$qiche->pull_some_thing('人');echo '
';//例子2:class A{ function foo() { if (isset($this)) { echo '$this is defined ('; echo get_class($this);//获得这个$this 代表的类 echo ")\n"; } else { echo "\$this is not defined.\n"; } }}class B{ function bar() { // Note: the next line will issue a warning if E_STRICT is enabled. A::foo();//在b类下调用A类的foo方法,获得的$this 是B类 }}$a = new A();$a->foo();@A::foo();//直接在类外调用A类的foo方法不能获取到A类(就是说不能在类外使用$this指代目标类)//$this->foo();//会报错$b = new B();@$b->bar();// Note: the next line will issue a warning if E_STRICT is enabled.@B::bar();echo '';
执行效果