Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87940 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42555 invoked from network); 26 Aug 2015 18:45:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Aug 2015 18:45:26 -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.181 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.181 mail-wi0-f181.google.com Received: from [209.85.212.181] ([209.85.212.181:35307] helo=mail-wi0-f181.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1F/E7-17883-5490ED55 for ; Wed, 26 Aug 2015 14:45:26 -0400 Received: by wicne3 with SMTP id ne3so53416153wic.0 for ; Wed, 26 Aug 2015 11:45:21 -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=OQNVr2HhD7cyLLVq82JxCs1+OOVSvoI8OJUhDLtFBG8=; b=JSHVxVGPpoNjHASJo++3HotSputpAqd5aY/3QB7JTqqAVkklrvBtMaTyjT7XILptTn cWJahR23TdWVfV7W9C9B3PqoqJmJMhY9iFcZMVxdhKVDYe4MT4m/3sS1tzXCb2Ns9Zcg Q3WJ9M/7/GC33HANhGTRkd1Fh/31rGOu0qQkHupzPo4yvfRBHm8VxYrdbp4qZ8hOYFMU asEDgQPJOLnteSX7i955Gt3Ssmq18Hjiw481AMXp28MLyucPyzIjqQEF83YS3sfcdHZ0 i4oBXDwTkw+6fVc4ypMq//pftAAHD+x6wyAqVORngpvt7ChUti/7kMuC+YRptyFaUzLp +XKQ== X-Received: by 10.180.108.35 with SMTP id hh3mr13886229wib.48.1440614721856; Wed, 26 Aug 2015 11:45:21 -0700 (PDT) Received: from [192.168.0.83] ([62.189.198.114]) by smtp.googlemail.com with ESMTPSA id ik8sm5148837wjb.8.2015.08.26.11.45.20 for (version=TLSv1/SSLv3 cipher=OTHER); Wed, 26 Aug 2015 11:45:21 -0700 (PDT) To: internals@lists.php.net References: <55DD4269.4090402@gmail.com> <6348DFA7-04BD-41BB-A500-17A8A531B56C@craigfrancis.co.uk> <55DDA4C9.9040603@gmail.com> <3C69BF4B-52E6-4D04-8601-8D23DFCC538E@craigfrancis.co.uk> <55DDD60F.5090509@gmail.com> <8C74463E-DBA2-4015-8159-0B44D973387F@craigfrancis.co.uk> Message-ID: <55DE0907.6040904@gmail.com> Date: Wed, 26 Aug 2015 19:44:23 +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: <8C74463E-DBA2-4015-8159-0B44D973387F@craigfrancis.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) Craig Francis wrote on 26/08/2015 18:07: > I provide examples to help explain that I (and I suspect most developers) default to using isset which works on either. > > Just because there is a function, which does not exactly roll off the tongue (plus the fun of the needle/haystack ordering issue), does not mean it gets used (even if it is the correct thing to use). That's all very well, but what is the Internals community supposed to do about it? Does the documentation need to be improved to point out that there is a better function to use for this case? > I say "or key" because developers use the isset function on both $var and $var['key']... yes, I know they are different, but when you are coding in PHP an isset check is an isset check (well it isn't, because the variable may technically exist). > > If this is a problem, maybe PHP should raise a notice when isset is used on arrays? It's only a problem in the same way that using file_exists() is a problem when you actually wanted the functionality of is_readable() - both functions exist, and it's not the language's responsibility to guess which you meant. >>> where NULL may be a perfectly valid value. >> It's not that NULL isn't a valid value; it's that "doesn't exist" isn't a meaningful state for a variable. It's like checking if the current line number is greater than 100, it shouldn't mean anything to the compiled program. See the SO answer I linked earlier for more thought experiments along these lines. > > I think you have been spending too much time in C. > > Most of the PHP code bases I've worked on set variables to NULL at some point (and they are not calling unset, because that isn't the intention). Perhaps my double negative made it unclear, so I will restate: there is nothing wrong with setting a variable to NULL. There is also nothing wrong with calling unset() on a plain variable, e.g. to make it obvious to readers of the code that this variable should not be used below this point. There IS something wrong with any code which needs to distinguish which of those two things happened, at run-time, because such code would be incredibly fragile and hard to follow. You could, if you wanted, emulate a boolean variable by using $foo=null for true, and unset($foo) for false, but why not simply have a boolean variable? [Incidentally, I know barely any C, but program PHP for a living.] Regards, -- Rowan Collins [IMSoP]