Re: [RFC] Allow specifying keys in list()

From: Date: Mon, 18 Jan 2016 12:50:28 +0000
Subject: Re: [RFC] Allow specifying keys in list()
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-90697@lists.php.net to get a copy of this message
Lester Caine wrote on 18/01/2016 12:35:
As someone still using 'extract' in legacy code, I can sort of see the logistics of this, but why not just extend 'extract' to use the current object rather than the symbol table. It already has handling for duplicate keys and to prefix the 'array' name to the resulting variables.
The main advantage I can see is that this is a whitelist-based approach - you state explicitly in your code what you expect the array to look like, and what variables you are assigning based on it. This is very different from "whatever's in this array, turn it into a variable". The "current object" was just one possible use case, have a look at some of the other examples in the RFC, such as: list(
    CURLOPT_GET => $isGet,
    CURLOPT_POST => $isPost,
    CURLOPT_URL => $url
) = $curlOptions; Note that $curlOptions probably had other things in it, $url may be an existing variable getting a new value. The best extract would give you is $curloption_10002, which isn't all that useful. Regards, -- Rowan Collins [IMSoP]

« previous php.internals (#90697) next »