Possible Duplicate:
PHP method chaining?
在我合作过的很多广告中, 我见过这样的事情:
$object->method()->anotherMethod();
我读过OOP的教程,这就是课程的写法,
<?php
class myClass {
public method() {
// do something
}
}
?>
对不起,但我对OOP是新手。
Possible Duplicate:
PHP method chaining?
在我合作过的很多广告中, 我见过这样的事情:
$object->method()->anotherMethod();
我读过OOP的教程,这就是课程的写法,
<?php
class myClass {
public method() {
// do something
}
}
?>
对不起,但我对OOP是新手。
如果您的方法返回 $Thi, 您可以使用上述样式 ($object- & gt; & getod ()- & gt; aotherMethod ()
) ) 。 只有在您的方法无法返回其它东西的情况下才能这样做, 例如, 名为 get something () code> 的方法预计将返回
anything code>, 但如果您的方法没有相关值可以返回, 您可以只返回 $This, 允许使用方法调用链 。
这叫做" http://en.wikipedia.org/wiki/Method_lagening" rel=“nofollow”>Method呼叫绑链 。对于你何时应该使用它,没有硬规则或快速规则,但我使用的一般规则是,当一系列物体方法经常被称作一个接一个时,方法链条就有意义,例如初始化功能。
In C#, I know that I can overload the constructor for a class by specifying it in the body of the class: public class MyClass() { public MyClass(String s) { ... } } This overrides the default ...
I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?
While designing ORM, what is the best approach to represent the relationship, performance-wise? I mean, out of the following two, which approach is best considering performance? class Employee { ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
Is there a standardized way to store classes in JSON, and then converting them back into classes again from a string? For example, I might have an array of objects of type Questions. I d like to ...
I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...
I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this Primary ). So, essentially in the constructor for the first, i can ...
A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...