On 19/01/16 01:35, Andrea Faulds wrote: >> $point = new Point(21, 42); >> list('x' => $x, 'y' => $y) = $point; > > You can't do `$x = $point['x'];`, so `list("x" => $x) = $point;` won't > work either. If you want list() support, implement ArrayAccess. > > We could potentially add some extension to list() for object > destructing, but I'm not sure I'd be happy with that, as list() has > thus far been an array-only thing. If we ever add object literals, then > we could do object destructuring with a symmetrical syntax.
Andrea, please bare with me as I'm trying to work out just what some of those long words actually mean. My real world example is from probably 15+ year old code which has to be re-factored these days to actually work. It creates an 'object' or list of objects as a multi level array to pass around and then uses extract() to give a set of variables some of which may be arrays themselves .... and some 'NULL' entries ... depending on just what the template is building. The 'parsing' will select a function depending on the type of a resulting element and perhaps pass on the extracted array if that is what is provided. I understand that modern practice is to actually define all the values being used ( and type them ) but the flexibility that used to be available seems to be lost by some of these new approaches when one now expects an array of 'objects' rather than an array of 'elements' ? I think that your 'destructuring' is the difference between my simply using the array value and having to find the value of a private variable in the object? Since I am invariably working with associated arrays, 'list' is not something in my toolkit, which is why using it will require rethinking, but simply tidying 'extract' to create a matching set of variables inside the object would make sense in my method of working. Every persistent object comes into me as an associated array, so I'm trying to see how this might improve my own code since the current practices are no longer PC. -- 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