Re: Re: function call chaining

From: Date: Wed, 20 Jan 2010 12:36:14 +0000
Subject: Re: Re: function call chaining
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-46838@lists.php.net to get a copy of this message
>>  I also think that: >>      $foo = (new bar())->someSetter(); > > someSetter() could return $this, although unlikely. The result of the line > above would be that the bar object is garbage collected after being created > & method someSetter() invoked. To keep it one would have to do: In very rare occassions I don't need to keep the object and I am fine with garbage collection. From garbage collection in PHP I know less, but isnt it so that: function blub() { $foo = new O(); // do long other stuff } gc's $foo only after the method is finished? function blub() { new O()->doSomething(); } would enable to collect this object before method ends. I am not sure if that works with php, but it might. > this could be simplified to: > >    $employees->findEmployee('John Smith')->increaseSalary(1000); > > This is the sort of reason why chaining is useful. It is also, IMHO, quite readable. That is exactly what I would love to see in PHP. Notation is also very similar to java notation. Cheers Christian

« previous php.internals (#46838) next »