当我们像这样使用两个对象运算符标记时,对象结构会是什么 -> ->?
我见过这样的事情:
echo ($hello->somethingA->somethingB);
这是什么意思?
我会尽力使我的问题更清楚:
当我们有 $domain->something;
(我们正在访问 $domain OBJECT 的某些 PROPERTY。精确?
当我们有 $domain-> ;something->run();
我们正在告诉 $DOMAIN OBJECT 的 some PROPERTY 来访问 run() 方法,
那么我们用: echo ($hello->somethingA. >somethingB);
?访问某些属性是否有意义?
- MEM
I've seen something like this:
echo ($hello->somethingA->somethingB);
What does this mean?
I will try to make my question more clear:
When we have $domain->something;
(we are accessing something PROPERTY of $domain OBJECT. precise?
When we have $domain->something->run();
we are telling our something PROPERTY of $DOMAIN OBJECT to access run() METHOD. precise?
So what are we telling with: echo ($hello->somethingA->somethingB);
? Accessing some properties property? Does this makes sense?
Thanks in advance,
MEM
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您正在访问财产的财产。显然,$hello 是一个具有名为 $somethingA 属性的对象。该属性是一个具有名为 $somethingB 的属性的对象。 $somethingB 显然是一个字符串或其他可以回显的类型。
Yes, you are accessing a property's property. Apparently, $hello is an object with a property named $somethingA. That property is an object that has a property named $somethingB. $somethingB is apparently a string or some other type that can be echoed out.
+1 给斯科特桑德斯,这里有一个例子来说明它:
+1 to Scott Saunders, here's an example to illustrate it:
其他答案中尚未探讨此问题的另一个方面。其他答案是您正在访问属性,而不是方法。但是 PHP5 的对象可以用于链接方法,也许这就是您所指的。
相反,
您可以这样做:
在每个方法中,返回
$this
就可以了。有关更多详细信息和灵感,请参阅本文:http:// /www.talkphp.com/advanced-php-programming/1163-php5-method-chaining.html
There is another facet to this that hasn't been explored in the other answers. The other answers you are accessing properties, not methods. But PHP5's objects can be made to chain methods, and perhaps that's what you're referring to.
Instead of this:
You can do this:
In each method, return
$this
and you're golden. See this article for more details and inspiration:http://www.talkphp.com/advanced-php-programming/1163-php5-method-chaining.html