Sorry, the extract() function will receives an array as first argument.

html::img(extract(['src', 'alt']);

2018-01-26 18:00 GMT-02:00 David Rodrigues <david.pro...@gmail.com>:

> Maybe you should see the extract() method. It will receive strings as
> varargs and will create an associative array with the string name and the
> value, similar to your first example.
>
> html::img(extract('src', 'alt'));
>
>
> 2018-01-26 16:16 GMT-02:00 Christian Schneider <cschn...@cschneid.com>:
>
>> Hi there,
>> I have a proposal for a shorthand notation of associative arrays borrowed
>> from another language:
>>         :$foo
>> would be equivalent to
>>         'foo' => $foo
>> and would work with array, list or []
>>
>> Motivation behind it, maybe someone else finds more good uses:
>>
>> 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
>>
>> 2) Simplifying list destructuring with non-integer keys, example taking
>> from http://php.net/manual/en/migration71.new-features.php#migrat
>> ion71.new-features.support-for-keys-in-list
>>         foreach ($data as ["id" => $id, "name" => $name]) {
>>    becomes
>>         foreach ($data as [ :$id, :$name ]) {
>>    which reduces redundancy.
>>
>> I implemented a minimal patch (2 lines are added to the parser) to
>> implement this which you can find at
>>         https://cschneid.com/php/php7_2/assoc_array_shorthand.patch
>>
>> What do you think, is this worth an RFC? I hope I didn't miss an existing
>> one :-)
>>
>> Regards,
>> - Chris
>>
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
>
> --
> David Rodrigues
>



-- 
David Rodrigues

Reply via email to