Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106642 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6891 invoked from network); 18 Aug 2019 21:54:13 -0000 Received: from unknown (HELO mail-wr1-f43.google.com) (209.85.221.43) by pb1.pair.com with SMTP; 18 Aug 2019 21:54:13 -0000 Received: by mail-wr1-f43.google.com with SMTP id q12so6447479wrj.12 for ; Sun, 18 Aug 2019 12:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:user-agent:in-reply-to:references:mime-version :content-transfer-encoding:subject:to:from:message-id; bh=evp9uxr7zwuIWJ6IlBuV073VauxLClZPlPB41/ZKHNQ=; b=MgreMFVApBbjIQyQzNW4rhfHt1gJYPs8RsXHoMRwcLX5dRuWqwaa+1EXFH1ZuuFbeb X9GZcqh/DhlRjkVqQKooXnUwdCyyC+9LFvXb0rMkoxFqkGblvcqXjQwAo0s004wolTfl XiJTPQiXbv3HMCP0YiEFtMYX0zLrlV1Pr50Nuf8SLFJtfhUJCts30EmIjf1ZpdWdVnMC pwOiypGlcNLBdKS+AKJRYPykdpLWka7mSkDiS+qcjt/2wm6qnCIjSBaseDocJiKWyhsF 9otdN/FD4TCm/kbV246ZnCNv9sDUpj6BRy2peZNF8oPCdXbfaXMyOKHydriT9mw5TGKn MZmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:user-agent:in-reply-to:references :mime-version:content-transfer-encoding:subject:to:from:message-id; bh=evp9uxr7zwuIWJ6IlBuV073VauxLClZPlPB41/ZKHNQ=; b=HIflskiFADbr1C2l0w+yA8uWHPKdwSpZEZNlCTAV/JAwSs8XnwB112i9EaG455h44p TJCAkslA0lR5yYwbsSNxdDjqTcATbwb7y7T14Ld8Klkv1GParXUrlDOy/rjHSP3DRvAG tAe3NYIflvKDatYZp5QduCF2w+FnJye/v8/r2DN90KqAgvg/4kCn3zSzhBX2gr2a6l9G GIZ0eQcsHhlhGRlt9SKbu6xIiJRxuLNTyJisGTxVJzfGIKHTkQcFzrvQxjLYrk6/NopF TJ0B3DfZ0VeVYFaEeCMNp92b1bCrwpKqCrVlZE/1kVsi1FlxRsqchDqnD1/2asxHmCWZ ZnTQ== X-Gm-Message-State: APjAAAUc7B5cdrX9mK0HRm3YUyJYMLahf3fQDOFvKGZWm9/FpI86Q2FP Me8f5n5TtElx53+wOBSwdzFyyO7M X-Google-Smtp-Source: APXvYqzjDQfgugafVae0Ceyvm7VAP6XlMSzT67IADNVxVUKeDUzNo0Gwk2kITrO+LAACdNmm+mw/WA== X-Received: by 2002:adf:ea89:: with SMTP id s9mr23810816wrm.76.1566156235858; Sun, 18 Aug 2019 12:23:55 -0700 (PDT) Received: from [192.168.0.12] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.gmail.com with ESMTPSA id u130sm25074602wmg.28.2019.08.18.12.23.52 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 18 Aug 2019 12:23:55 -0700 (PDT) Date: Sun, 18 Aug 2019 20:23:50 +0100 User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: internals@lists.php.net Message-ID: Subject: Re: [PHP-DEV] get_class_vars() and typed properties From: rowan.collins@gmail.com (Rowan Collins) On 18 August 2019 11:14:52 BST, Nicolas Grekas wrote: >Le dim=2E 18 ao=C3=BBt 2019 =C3=A0 11:59, Benjamin Morel >a >=C3=A9crit : > >> Hi Internals, I just noticed the following behaviour: >> >> class A { >> public int $a; >> public ?int $b; >> public ?int $c =3D null; >> } >> >> $a =3D new A; >> >> var_export(get_object_vars($a)); >> var_export(get_class_vars('A')); >> >> Result: >> >> array ( >> 'c' =3D> NULL, >> ) >> array ( >> 'a' =3D> NULL, >> 'b' =3D> NULL, >> 'c' =3D> NULL, >> ) >See https://bugs=2Ephp=2Enet/78319 >get_class_var() does the most useful thing, thus the correct one to me >and >the use cases I have=2E This is a nice example of something I said when typed properties were bein= g added: "uninitialised" is a new special state, distinct from "non-existen= t" and "null"=2E As such, a non-nullable typed property without default val= ue is impossible to represent accurately without having a representation of= that state=2E One rather ugly possiblity in this case would be to have the values return= ed be "uninitialized", so that accessing the array keys was valid, but acce= ssing the values gave an Unitialized Value Error=2E That would be pretty ho= rrible for backwards compatibility, though, particularly for get_class_prop= erties, where there's no chance for the constructor to run and set up a rea= l value=2E Regards, --=20 Rowan Collins [IMSoP]