Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88478 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44800 invoked from network); 24 Sep 2015 17:42:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Sep 2015 17:42:48 -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.212.177 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.177 mail-wi0-f177.google.com Received: from [209.85.212.177] ([209.85.212.177:38271] helo=mail-wi0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5D/32-22452-41634065 for ; Thu, 24 Sep 2015 13:42:45 -0400 Received: by wiclk2 with SMTP id lk2so123272710wic.1 for ; Thu, 24 Sep 2015 10:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:references:to:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=nmUekikH2wR5486J53do1IZ4zA/gMrmjzUyhnfDFZ0c=; b=TiU+8urYkM0XrU6TIGYuF9oSFjSt846RFkIErOPyK3GXH/BJmH6u2zS+4tXUqt1l6u nY2Xc+y5VhGhz9UcpM385X477M7AoOZH/DgIVdhOpaP0rdKQwkiBhoc59HurVOoDun7+ RDgTV7bviXvhmd7dVavoKcl/hxS8IijM8k0tfE1F1zb9OPX5GLmmZOoHck+N/+qplrH9 MUKM5WPi1GyjdxN8dDLd4GNv3kH+z6bHnN9wF4AA5jHtsuGxJw4Re5md6yxMJIpNwY3+ Hubx7sP4Q/SAC46PUm3tWPl6n/DYHIrWRKFrcssiBxJIG3opCWOJtQzbUUd+ZFAI/J+M vcFA== X-Received: by 10.194.202.137 with SMTP id ki9mr1015561wjc.16.1443116562095; Thu, 24 Sep 2015 10:42:42 -0700 (PDT) Received: from [192.168.0.119] ([62.189.198.114]) by smtp.googlemail.com with ESMTPSA id ki7sm13312080wjc.28.2015.09.24.10.42.40 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 24 Sep 2015 10:42:41 -0700 (PDT) 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> <56009C96.5090504@php.net> <56013228.50504@gmail.com> <5601E01E.6080606@php.net> <56027C79.9020404@gmail.com> <5602BFB3.7090707@php.net> <5602DE27.4080500@lsces.co.uk> <5602EEF8.2090500@gmail.com> To: PHP Internals Message-ID: <560435F2.4030408@gmail.com> Date: Thu, 24 Sep 2015 18:42:10 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] PHP 7.1 - Address PHPSadness #28? From: rowan.collins@gmail.com (Rowan Collins) Rowan Collins wrote on 23/09/2015 21:15: > On 23 September 2015 20:04:57 BST, Ryan Pallas wrote: >> I dislike this because it makes refactoring harder. > What's more, the function is not dereferencing a variable to get its value, it is looking up a name in the symbol table, so the magic syntax that makes it look like you're using the variable is misleading. Talking of refactoring, I thought of an interesting example of the ambiguity/confusion a combined exists() function could create. For any normal function the two definitions below should be equivalent - you can refactor the use of $GLOBALS by importing the variable with the "global" keyword. function foo() { var_dump(exists($GLOBALS['test'])); } function bar() { global $test; var_dump(exists($test)); } I haven't actually built François's branch to test, but based on behaviour of existing functions [e.g. https://3v4l.org/X0tOk], I predict the following output: foo(); // bool(false) bar(); // bool(true) The "global $test" is the closest PHP comes to a variable declaration - the variable now exists in the symbol table, even though there was no global variable with that name to import. Even more confusingly, it has a side-effect on the original function: foo(); // bool(true) That happens because "global $test" is basically "$test =& $GLOBALS['test']", so has to create the global variable in order to reference it. This is completely invisible to most programs, because it gets initialised to null, so isset() returns false consistently. [https://3v4l.org/f4dm2] This is the kind of odd edge-case you end up with when you a) treat a variable's existence as an accessible property; and b) make that check appear to be the same as checking for an item in an array. With the two functions I've proposed, you at least wouldn't be led astray by an automated refactoring tool because this would give an error, rather than a surprising result: function bar() { global $test; var_dump(hasitem($test)); } And you would have to specifically change it to this instead, clearly a different type of test: function bar() { global $test; var_dump(variable_exists('test')); } Regards, -- Rowan Collins [IMSoP]