0

I have seen both of these syntaxes for adding constraints to an existing Fluent/Eloquent $query (such as when appending a constraint based on a conditional):

$query = $query->where( 'id','=',1 );

and

$query->where( 'id','=',1 );

Is there any practical difference between them?

dspitzle
  • 740
  • 2
  • 9
  • 26

1 Answers1

1

No difference at all. In this case $query is an object and it will internally set the filter, but it also returns itself, to provide chaining:

$query->where( 'id','=',1 )->where( 'name','=', 'antonio' );

So those two are exactly the same.

$query = $query->where( 'id','=',1 );
$query->where( 'id','=',1 );
Antonio Carlos Ribeiro
  • 86,191
  • 22
  • 213
  • 204
  • Thanks, that's what I was hoping. Wouldn't adding the redundant assignment technically add a tick or two to the processing time? – dspitzle Mar 21 '14 at 19:30
  • Oh, yes, it might, but this is an object and objects are referenced by it's pointers (address in memory), so it would be really just a tick. – Antonio Carlos Ribeiro Mar 21 '14 at 19:39