php - 扩展类携带对象
我试图早些时候问这个问题,但我想我匆忙地提出了这个问题,并没有理解我的想法......
$this 的值和对象是否传递给扩展类?
<?php
class bar {
public function foo( $t ) {
$this->foo = $t;
}
}
class foo extends bar {
public function bar () {
return $this->foo;
}
}
$b = new bar();
$b->foo('bar');
$f = new foo();
echo $f->bar();
?>
如果没有,是否有另一种减速(而不是扩展)可以在不将父类的对象传递给子类的情况下进行?
问候,
菲尔
I tried to ask this question earlyer but I think I rushed the question and did not get accross what I was thinking...
Does the value and objects of $this get passed to an extened class?
<?php
class bar {
public function foo( $t ) {
$this->foo = $t;
}
}
class foo extends bar {
public function bar () {
return $this->foo;
}
}
$b = new bar();
$b->foo('bar');
$f = new foo();
echo $f->bar();
?>
if not, is there another decleration (instead of extends) that does without passing the object of the parent class to the child class?
regards,
Phil
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的示例将产生
Undefined property: foo::$foo
错误。我认为您尝试使用的是static
属性:然后是以下内容:
... 将回显
bar
,这看起来像是您想要实现的目标。Your example would yield an
Undefined property: foo::$foo
error. I think what you're trying to use is astatic
property:Then the following:
... would echo
bar
, which looks like what is you're trying to achieve.