Am 28.01.2018 um 00:29 schrieb Sara Golemon <poll...@php.net>:
> On Fri, Jan 26, 2018 at 4:49 PM, David Rodrigues <david.pro...@gmail.com 
> <mailto:david.pro...@gmail.com>> wrote:
>> Sorry. I mean "compact()" instead of extract() (it basically does the
>> oposite hehe), I confused everything in a hurry. Sorry.
>> 
>> So the real example is: html::img(compact('src', 'alt'));
>> 
>>> On Fri, Jan 26, 2018 at 12:16 PM, Christian Schneider 
>>> <cschn...@cschneid.com> wrote:
>>>> 1) Emulating named parameters with associative arrays like
>>>>        html::img([ 'src' => $src, 'alt' => $alt ]);
>>>>   could be written as
>>>>        html::img([ :$src, :$alt ]);
>>>>   which encourages consistent naming of variables and parameters
>> 
> I see nothing in this proposal that compact doesn't already do quite well.


Yes, it is syntactic sugar to remove verbosity. Using compact() has two 
problems for me:
1) It is verbose especially if the assoc-as-poor-man's-named-parameter approach 
is used frequently. A bit like array() vs. [].
2) More importantly: It hides the variable being used: 'src' instead of $src 
which makes it harder to search for the variable or statically analyse the code.

- Chris


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to