Re: Set object properties inline

From: Date: Wed, 01 Jun 2016 09:40:08 +0000
Subject: Re: Set object properties inline
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-93666@lists.php.net to get a copy of this message
On 01/06/16 03:15, Jesse Schalken wrote: > For large structures, this gets verbose very quick. There is a good example > of this here > > <https://github.com/jesseschalken/fail-whale/blob/72870b37c4c21d19f17324a966344ec476b432a7/src/FailWhale/Introspection.php#L22> > involving > 18 unnecessarily variables. > > I can remove the local variables by defining setters for all the properties: It's nice to see a page of code I can actually read and follow without having to dig out the 'new functions' crib sheets ... The main reason I recognise the code is it has elements I was working with carried over from the PHP4 stuff I started with and I'm still at the alternate solution ... $static1 = new Data\StaticVariable; $static1->name = 'variable name'; $static1->value = $unknown1; $static1->functionName = 'blahFunction'; $static1->className = null; Morphed into simply passing an array to the constructor ... $static1 = new Data\StaticVariable( array( 'name' => 'variable name', 'value' => $unknown1, 'functionName' => 'blahFunction' ) ); // className defaults to null Of cause the short cut at that time was to drop the names and simply count the variables, but what this replaces is all the complications of named parameters and allowed passing objects in such as '$unknown1' -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

« previous php.internals (#93666) next »