Re: Shorthand proposal for associative arrays

From: Date: Sun, 28 Jan 2018 02:51:08 +0000
Subject: Re: Shorthand proposal for associative arrays
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-101715@lists.php.net to get a copy of this message
Am 28.01.2018 um 00:29 schrieb Sara Golemon <pollita@php.net>: > On Fri, Jan 26, 2018 at 4:49 PM, David Rodrigues <david.proweb@gmail.com > <mailto:david.proweb@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 <cschneid@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

« previous php.internals (#101715) next »