Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88247 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9966 invoked from network); 16 Sep 2015 15:41:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Sep 2015 15:41:41 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.46 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.215.46 mail-la0-f46.google.com Received: from [209.85.215.46] ([209.85.215.46:33966] helo=mail-la0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/F0-04557-4BD89F55 for ; Wed, 16 Sep 2015 11:41:40 -0400 Received: by lahg1 with SMTP id g1so102916517lah.1 for ; Wed, 16 Sep 2015 08:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=V9/G6lrgdc8wQ6TrAVk9XTl1bWn1W6VAt3zhLau+Nmc=; b=eLh19bC8Roj88nNfzl+AwDxN1Pd86EV1x1NiP+Cgk3BxKMVtnaov1a1X83QnxZp2nI XicWS3J1SR528kdCjPY82iz3zHDrwdSOP6dcrTcM9t7WjmlzaguOaJizfPcfWVXiuDc5 NU9kPRMWsdp0MAEDuCP21XZFziPSow5qZIpPVOztdJ0MpwcvyOi8Tt8C9jccHPM0Urdp dQE4hN/Xro6bnPdtlFv802k+WLozTMjTcP3lXsHC/6Wfz+leONJSIjywYfP3iL6pPU0a S2k1Gj/1uiyguD5hPMfe/vzVSUsYBgBT18KZFXR/GDCldiUhO/S4oyk1VrZt1Ymdacez zNpQ== X-Received: by 10.152.10.71 with SMTP id g7mr30185964lab.61.1442418097695; Wed, 16 Sep 2015 08:41:37 -0700 (PDT) Received: from [192.168.0.127] ([62.189.198.114]) by smtp.googlemail.com with ESMTPSA id p8sm4189309laf.12.2015.09.16.08.41.36 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Sep 2015 08:41:36 -0700 (PDT) To: internals@lists.php.net References: <55E5EBBF.6020803@gmail.com> <0BA3A129-D356-4781-B6DE-E2B5A7924AE2@craigfrancis.co.uk> <55E6EC36.6090301@gmail.com> <9AF329EC-99A5-412D-A52B-432627A5520F@gmail.com> <6F4D91EE-B56E-4B83-B1AF-598C3F6897FC@craigfrancis.co.uk> <55F07BA4.2000204@gmail.com> <55F6B911.9080400@gmail.com> <96BE7F01-D04B-483B-B1A3-B45CED6DFCDC@craigfrancis.co.uk> <55F6F08C.1020506@gmail.com> <0BEF6D82-CB5F-49F6-A3A4-3267924A0CDA@thesba.com> <55F78D90.7090601@php.net> <55F7CE3E.1040804@lsces.co.uk> <55F93E67.3000806@gmail.com> <55F945F7.8010402@lsces.co.uk> <55F94B25.8070603@gmail.com> <55F95439.5070306@php.net> <55F95F26.5080409@gmail.com> <55F963E7.2040800@php.net> <55F9668F.4010804@gmail.com> <55F96DF5.8030606@php.net> <55F96F02.2080601@gmail.com> <55F9889F.1060008@lsces.co.uk> Message-ID: <55F98D81.6010109@gmail.com> Date: Wed, 16 Sep 2015 16:40:49 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: <55F9889F.1060008@lsces.co.uk> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PHP 7.1 - Address PHPSadness #28? From: rowan.collins@gmail.com (Rowan Collins) Lester Caine wrote on 16/09/2015 16:19: > Found the little gem I was trying to remember ... extract() > Import variables into the current symbol table from an array > THAT was the process I've seen used in libraries resulting in 'NULL' Yes, extract(), like variable-variables ($$foo), can dynamically create local variables, and therefore lead to cases where you don't know, until runtime, whether a variable exists at all. > I appreciate this is all very far > fetched, since one could check things on the array side, but it is where > I've seen mistakes with handling the generated variables Indeed. Until Craig's template / View example, I'd never seen extract() actually used for anything remotely defensible, but it is there, so it's a fair question whether we consider it a "bad" function in some way. My inclination is that even if you're using such a mechanism to dynamically define variables, it would still a bad idea to write code like this: if ( exists($a) ) { ... } elseif ( is_null($a) ) { ... } else { // use $a } There is clearly a lot of hidden meaning here - what exactly are the three states of the variable representing, in domain terms? - which would be better exposed with another variable or something. For instance, if we make $a an object, you might instead write this: if ( $a->is_dummy_data() ) { ... } elseif ( $a->is_system_default() ) { ... } else { // use $a->value } If the extract() was being used to make the view code more readable in the first place, the exists() defeats rather than assists in that objective, in my opinion. Regards, -- Rowan Collins [IMSoP]