On Wed, Jun 1, 2016 at 7:40 PM, Lester Caine <les...@lsces.co.uk> wrote:
> 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' > This works fine to remove the temporary variable but compromises two things that I think are very important: 1. IDE tooling and static analysis. An IDE can't autocomplete property names as array keys, because it doesn't know the array keys are properties, nor can it ensure that the properties actually exist, are visible, and are being assigned the correct type. If I do a "Find Usages" on a property, it may appear to be only read and never set, implying I can remove the property and replace all the reads with the default value. Any static analysis tool would have the same trouble. 2. Performance. The code spends time building a temporary hash table just to loop over it, look up each key in the object's property table, check visibility, check type, assign it, and discard the hash table. That's a lot of overhead just to assign some properties. With a dedicated inline property assignment syntax, a normal bunch of "assign property" bytecode instructions can be output and the PHP runtime will cache the property offsets and assign them directly, and can elide the property type check if the optimiser knows it will pass. HHVM can even burn the property offset right into the compiled machine code. That's *way *faster. (At least that's how I was told it works when I asked here a couple of weeks ago.) > -- > 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 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >