Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:88287 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 53851 invoked from network); 17 Sep 2015 19:52:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Sep 2015 19:52:38 -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.182 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.182 mail-wi0-f182.google.com Received: from [209.85.212.182] ([209.85.212.182:37901] helo=mail-wi0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/30-50575-50A1BF55 for ; Thu, 17 Sep 2015 15:52:37 -0400 Received: by wiclk2 with SMTP id lk2so4965274wic.1 for ; Thu, 17 Sep 2015 12:52:34 -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=CAmAhjNGMMcoS0WmDioWBfehCGKmDf9YzvEObo8Aow4=; b=rylOUEMUepXaeFjibWWA/UR5SDQ0IE+Fbw9LD2fTRLYtNZI4pkhujLV8WsrEktFwjX xVsnKS5owCTwdaAprlvSfg4R803Cv8FmzfuOk+GSQKzh4wLpTuMsVO7qxgnGsk2OpTL3 DdJxa5j1AcLjbP3f5MXnDq46CIuakvx2vlS7IC4JpK4q/ubbm2FYoWrzwqJOZfN9Wp5k +Z2fCEbf2SHECx5P8Ks9ox+kR8LDp1TOeekGXNhhTDD0wheB7/+mvgOeG28i7fr+4TWy SFS2DSrGavJwS0obemXYlEM13rRzplwBYDyfxGCLt4r2EBskY6lK9D1EN3hmHse4+KFb M/Kg== X-Received: by 10.180.24.102 with SMTP id t6mr33907779wif.83.1442519553987; Thu, 17 Sep 2015 12:52:33 -0700 (PDT) Received: from [192.168.0.127] ([62.189.198.114]) by smtp.googlemail.com with ESMTPSA id pg5sm5046600wjb.21.2015.09.17.12.52.33 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Sep 2015 12:52:33 -0700 (PDT) To: Lester Caine , internals@lists.php.net References: <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> <55F72CA9.2060301@gmail.com> <09369945-76FE-4E08-9C2C-15FB0577AD27@thesba.com> <55F752E7.9070801@gmail.com> <55F9B4C7.3050700@gmail.com> <440C64A2-4B4F-4AEF-ACE3-F3A6637EBAB6@thesba.com> <55F9D704.5050002@lsces.co.uk> <55F9EFA2.9020908@lsces.co.uk> <0022A1D9-DC37-4F49-B58E-FBED5AF872BA@gmail.com> <55F9FAB3.2050100@lsces.co.uk> Message-ID: <55FB19CB.7080707@gmail.com> Date: Thu, 17 Sep 2015 20:51:39 +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: <55F9FAB3.2050100@lsces.co.uk> Content-Type: text/plain; charset=utf-8; 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 17/09/2015 00:26: > If the 'variable' exists but is NULL you create a default element of > that name. If the 'variable' does not exist nothing gets created. So > > exists($checklist) { > is_null($checklist) { create default/empty object(); } > else { create populate odbject($checklist); > } else { > display code in place of object; > } Thanks, this is an interesting example of how the function could be used. To paraphrase, your 3 states being communicated from the controller to the view are: a) Do not use this object, even if you want to. b) If you want this object, you may create a default one. c) If you want this object, create it with these parameters. You then want to use null for case (b), so need a "very null" value (non-existent variable) for case (a). I think I would personally find it more readable if null was reserved for case (a), which feels closer to the normal meaning of NULL as "missing data", like in a database. Some other terminal value would then need to be found for case (b) - a string like '__DEFAULT__', for instance (if $checklist is normally an integer, literally any string will do; if it's normally a string, you've got to be more careful with your choice of reserved word). Or, I might architect it in a completely different way, and pass around an object that can lazy load its own data, rather than lazy loading the object itself based on a scalar value. But I can't say that the proposed approach is "wrong", exactly. If you're so eager to do this that you'd be willing to make the application have a minimum PHP version of 7.1, I suppose it's an argument in favour of changing the language to allow that. But since there are plenty of alternative ways to architect this in the current language, it seems slightly artificial. As a straw man example, if the language allowed me to assign colours (with a 'u', in the spelling, because I'm British :P) as metadata to a variable, I could write it like this: switch ( get_colour($checklist) ) { case COLOUR_RED: default: // display code in place of object; break; case COLOUR_YELLOW: // create default object break; case COLOUR_GREEN: create_object($checklist); break; } Obviously, that's a stupid idea, but in a sense that's what you're actually asking for - a piece of metadata about the "state" of the variable, alongside its value; it just so happens that there's a candidate piece of metadata that would be fairly easy for the language to give you. With null vs non-null, you have two states, with exists() you could distinguish a third state - but that third state doesn't really have anything to do with non-existence, it's just an extra piece of information that the controller wants to pass to the view. What would really be handy in a case like this is the ability to create your own null-like values, guaranteed to be distinct from all other values: type hidden extends \php\basetypes\terminal {} type default extends \php\basetypes\terminal {} $checklist = hidden; gettype($checklist); // 'hidden' $checklist == hidden; // true $checklist == deafult; // false isset($checklist); // true Maybe even: type missing extends \php\basetypes\null {} $foo = missing; isset($foo); // false is_null($foo); // not sure... Regards, -- Rowan Collins [IMSoP]