Still on the PHP-OOP training wheels, this question may belong on failblog.org. =)
What are the benefits of method chaining in PHP?
I'm not sure if this is important, but I'll be calling my method statically. e.g.
$foo = Bar::get('sysop')->set('admin')->render();
From what I've read, any method which returns $this is allowed to be c...
is it acceptable/good-practice to use the method chaining pattern on value objects (like, returning a new object instead of this)? are there cases out there where this solution is implemented ?
I cannot think of any drawbacks, but I'd like to hear your point.
...
I was reading up some things about how to design a library or API well, and stumbled across Joshua Bloch's great talk at Google Tech Talks. Now although I am nowhere near a professional API developer, I think programming a bunch of classes/functions is a similar, although much scaled-down version of the same thing - clear-cut separation ...
Hi,
are there any approaches, given a statement like the following
First().Second();
to know from within First() whether/when Second() has executed?
Reference: http://martinfowler.com/dslwip/MethodChaining.html
...
I would like to know whether there's a way to chain methods on a newly created object in PHP?
Something like:
class Foo {
public function xyz() { ... return $this; }
}
$my_foo = new Foo()->xyz();
Anyone know of a way to achieve this?
...
I don't think a function/method should ever return voidinstead, it should return this. That's why I was surprised to find out that this doesn't work:
$('buttonContainer').getElement('input').set('value', this.get('value') + ' ');
What the code is suppose to do is find an <input> that is a child of the element with id attribute value ...
When a function is chained in JQuery, what is the order of operations?
Example 1
$(selector).fun1(val,{fun2(){ }}
Example 2
$(selecter).fun1().fun2().fun3()
...
Hi
I am using method chaining for my class structure.
So my problem is that , how could i break my chain when error occurred in some function.
Below is my code:
<?php
class demo
{
public __construct()
{
$this->a='a';
$this->b='b';
$this->error = false;
}
p...
When programming against a fluent API or just using method-chaining, I've seen the style mostly like this:
var obj = objectFactory.CreateObject()
.SetObjectParameter(paramName, value)
.SetObjectParameter(paramName, value)
.DoSomeTransformation();
What is the reasoning behind putting the dot at the beginning of the line ins...
Hello!
I cannot find a simple example about my question above: how can i detect the end of a method chain?
I'm just looked Zend_Db_Select for example but this one is too complex for this simple question i think.
Is it possible to catch the 'end' of a method chain in PHP?
thanks,
fabrik
...
Hi.
I want to show some progress information of a server side procedure (which in fact is an ffmpeg re-encoding).
The best way I though of was to use two different $.ajax() calls on myscript like this:
1) when the form is submitted (which would trigger the re-encoding) one $.ajax() would start the re-encoding like this:
$.ajax({
...
Not in terms of readability, naturally, since you can always arrange the separate methods into separate lines. Rather, is it dangerous, for any reason, to chain an excessively large number of methods together? I use method chaining primarily to save space on declaring individual one-use variables, and traditionally using return methods i...
I've coded an experimental function which makes passed objects chainable by using high order functions. It's name is "chain" for now, and here is a usage example;
chain("Hello World")
(print) // evaluates print function by passing "Hello World" object.
(console.log,"Optional","Parameters")
(returnfrom) // returns "Hello World"
I...
I've seen in many Java code notation that after a method we call another, here is an example.
Toast.makeText(text).setGravity(Gravity.TOP, 0, 0).setView(layout).show();
As you see after calling makeText on the return we call setGravity and so far
How can I do this with my own classes? Do I have to do anything special?
...
If I have a method chain like the following:
var abc = new ABC();
abc.method1()
.method2()
.methodThrowsException()
.method3()
;
assuming I've defined method1(), method2() and method3() as
public ABC method1() {
return this;
}
and methodThrowsException() as...
Having Collection initializers in C# and being allowed to define properties of a class without having to call the constructor, is there any point in using Method Chaining in C#?
I can't see any. Maybe I'm missing something here?
Thanks
...
i have come across fluent api while studying DSLs. i have searched alot on FLUENT API..the basic conclusion which i could draw out was that fluent api uses method chaining in order to make the code fluent. but i cannot understand that in object oriented languages we can always create an object and can call the methods related to it. then...
I have the following code,
<?php
class Templater
{
static $params = array();
public static function assign($name, $value)
{
self::$params[] = array($name => $value);
}
public static function draw()
{
self::$params;
}
}
$test = Templater::assign('key', 'value');
$test = Templater::draw();...
Example 1:
SomeObject someObject = new SomeObject();
if (someObject.Method())
{
//do stuff
}
//someObject is never used again
vs
Example 2:
if (new SomeObject().Method())
{
//do stuff
}
Is there any benefit to using the first method over the second, or vice versa?
...
update
Since one effect of these functions is to provide a way to use method chaining on methods that would not normally support it *, I'm considering calling them chain and copychain, respectively. This seems less than ideal though, since the would-be copychain is arguably a more fundamental concept, at least in terms of functional pr...