Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93561 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30114 invoked from network); 26 May 2016 11:59:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2016 11:59:26 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.46 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.46 mail-wm0-f46.google.com Received: from [74.125.82.46] ([74.125.82.46:36954] helo=mail-wm0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 02/62-17600-D15E6475 for ; Thu, 26 May 2016 07:59:26 -0400 Received: by mail-wm0-f46.google.com with SMTP id z87so96536995wmh.0 for ; Thu, 26 May 2016 04:59:25 -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-transfer-encoding; bh=xo6cMObiMe6NApahEEI+iQmO9C2FAWoQTYBtgqSzQQg=; b=S9Z7S3/OahUxUgSk3N8K0IpnK4FsxWWnu2l+p5eDt9Dr8Xko1foYLYSYwgnViETxjT 0lISadd5r0Iv8Asp+b6xvvFMQHwskdgyqOtMiSzGvma9zTqkfHbept5Xo+LT603/RVJ3 Mqfs1Bav8tIY6mB3k2mr8by2oa1yQ0nwtPq2mwGPlLZs6Kgei1dssp5I62A9SaPhx3lD WsCQigVxIvv6IiM6uUgDHiN+Y2zE/AiPTgT97nn23tgyx0wzhSNBQraIdNADbaL/noBI JfJMQFv3LlHwH6fFJRNjvrIDeSNBD4yiG8SanCA35sNfFU0f4ce9gJpA5RdvZB/BDKA6 UHfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=xo6cMObiMe6NApahEEI+iQmO9C2FAWoQTYBtgqSzQQg=; b=e14q9Jrouh07IrOghicOCWFBUgZjpTsydmiOs5S47wUEBMIBPIPomKyUWvFXWsA5Sb WrjGPGiOtl3sm92+XNZz5Yx3IIKsRaZEqWfvhrIFcrxPnh0bubnWGmiAwvnEFNZosyTa JMZzHYn0UZDUvdB0CizpyxeZBlLYcSZq11xYoUpFTAtqyOt49SX4OPBwMZrLnisgGEDK DunYeo2+IT2y2Ciqgvc63jy837byNgDNWx5yyOv6bqp/R+exZS8brctkJXjTUxhIdYx1 hNtLK0MVn10X5Glpl08rX8eA3ngzNVYPDzyxEwRupLruKb/7wIUwX2f9iSVx2nl4RvDA 0K0Q== X-Gm-Message-State: ALyK8tJ2BmhaPOdEUvaZjhZndAmhkD+2cgK4y5uPv7EEyAZZY2oMpg7/ZGb20MdWn/gaGQ== X-Received: by 10.28.210.75 with SMTP id j72mr3175454wmg.31.1464263963401; Thu, 26 May 2016 04:59:23 -0700 (PDT) Received: from [192.168.0.98] ([93.188.182.58]) by smtp.gmail.com with ESMTPSA id a75sm3187640wme.18.2016.05.26.04.59.22 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 May 2016 04:59:22 -0700 (PDT) To: internals@lists.php.net References: <7B.12.14311.F79C5475@pb1.pair.com> <1b12b09f-f190-dca0-51d9-468e9c571268@fleshgrinder.com> <4ec823c6-b039-fc91-7c78-60d67719cd81@gmail.com> <00482771-3a07-06cf-ee8d-cd83a301c7e7@fleshgrinder.com> <1ac579b7-6bf3-f362-c045-0261abcfa17c@fleshgrinder.com> <2f058fee-f230-739f-4ed5-ff7d0cabe924@fleshgrinder.com> <7c3f6b51-f93b-c69f-a592-7bb0a00586e6@gmail.com> <528dd5dc-0e17-d766-a83f-02e2429277fa@fleshgrinder.com> Message-ID: Date: Thu, 26 May 2016 12:57:39 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <528dd5dc-0e17-d766-a83f-02e2429277fa@fleshgrinder.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: rowan.collins@gmail.com (Rowan Collins) On 26/05/2016 11:49, Fleshgrinder wrote: > On 5/26/2016 12:39 PM, Rowan Collins wrote: >> On 26/05/2016 11:16, Fleshgrinder wrote: >>> $o = (object) ['x' => null]; >>> var_dump(isset($a->x)); // false >>> var_dump(property_exists($a, 'x')); // true >> >> Apart from a typo in your example (you change from $o to $a), this is >> already the current behaviour, and always has been: https://3v4l.org/NeqGl >> >> isset() is really very simple: if the thing your accessing would give >> you the value null, it returns false, otherwise it returns true. >> >> Regards, > > Now I feel stupid but I guess I got lost myself. :P Heh, no worries, easily done. :) > This means it is even simpler, we just have to add the E_NOTICE and be > done with it. > > $g = new class { public $x; }; > > var_dump($g->x); // null + E_NOTICE Uninitialized > var_dump(isset($g->x)); // false > var_dump(property_exists($g, 'x')); // true > var_dump(is_null($g->x)); // true + E_NOTICE Uninitialized > var_dump($g->x == null); // true + E_NOTICE Uninitialized > var_dump($g->x === null); // true + E_NOTICE Uninitialized > > This behavior would be true for all variations: > > class A { > > var $x; > > public $x; > > public int $x; > > public ?int $x; > > } > > No notice for the following: > > class A { > > var $x = null; > > public $x = null; > > public int $x = 0; > > public ?int $x = null; > > } > I am definitely in favour of this from a language point of view. The notice is warning about *initialization*, not *declaration*, so it makes sense to warn on "var $foo" and not "var $foo = null". The only thing I'm not sure is what the impact would have on the internals, which may be why it doesn't already work that way. With a simple variable the notice can be easily raised based on the variable name not being in the current symbol table; with an object property, the name *is* in the relevant table, because it's been *declared* even though it hasn't been *initialized*. Thus you need some extra flag to track that a declared property exists but has never been written to. But it sounds like typed properties require adding some such overhead anyway... Regards, -- Rowan Collins [IMSoP]