Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93574 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73229 invoked from network); 26 May 2016 16:48:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2016 16:48:40 -0000 Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.25.164 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.164 mx208.easyname.com Received: from [212.232.25.164] ([212.232.25.164:55334] helo=mx208.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2A/7A-17600-6E827475 for ; Thu, 26 May 2016 12:48:39 -0400 Received: from cable-81-173-133-15.netcologne.de ([81.173.133.15] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1b5ySQ-0006NU-Oj; Thu, 26 May 2016 16:48:26 +0000 Reply-To: internals@lists.php.net References: <20160525215208.034FC1A801B3@dd1730.kasserver.com> <5fd54aa0-4fdf-c1e7-eae8-765aa89c8498@fleshgrinder.com> To: Tom Worster , php-internals , James Gilliland , Thomas Bley , ajf@ajf.me Message-ID: <871d57cd-cf8d-626c-8bfc-4c23482fb38d@fleshgrinder.com> Date: Thu, 26 May 2016 18:48:20 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="llhltFwfIvMXDF9GrJvf4SNncPV6RdJsn" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: php@fleshgrinder.com (Fleshgrinder) --llhltFwfIvMXDF9GrJvf4SNncPV6RdJsn Content-Type: multipart/mixed; boundary="8Q76XPPtMrV9DD7daoueXGE1s5IsMoMb5" From: Fleshgrinder Reply-To: internals@lists.php.net To: Tom Worster , php-internals , James Gilliland , Thomas Bley , ajf@ajf.me Message-ID: <871d57cd-cf8d-626c-8bfc-4c23482fb38d@fleshgrinder.com> Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties References: <20160525215208.034FC1A801B3@dd1730.kasserver.com> <5fd54aa0-4fdf-c1e7-eae8-765aa89c8498@fleshgrinder.com> In-Reply-To: --8Q76XPPtMrV9DD7daoueXGE1s5IsMoMb5 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 5/26/2016 6:40 PM, Tom Worster wrote: > On 5/26/16, 12:30 PM, "Fleshgrinder" wrote: >=20 >> The problem is a completely different one, how should the following co= de >> behave? >> >> class A { >> >> public int $x; >> >> } >> >> (new A)->x; >> >> The property has no value assigned but it is being accessed. The curre= nt >> PHP behavior is to simply initialize it with null. But this is >> impossible according to the type definition. >> >> There are not many ways to handle this. I think we already had all of >> them proposed: >> >> 0. Fatal error after __construct was called. >> 1. Fatal error and abort. >> 2. Initialize with appropriate type. >> 3. Initialize with null. >=20 > Under another 5th option, the problem you state does not arise. Disallo= w > "public int $x;". Under this option you may declare $x with type int an= d > an initial value or you may declare $x without type but you may not > declare $x with type (nullable or not) and undefined initial value. >=20 > Tom >=20 This would be a valid approach too, yes. I personally would be against it because I do not want to initialize all my properties. class A { private int $x; public function getX() { if (empty($this->x)) { $this->x =3D 42; } return $this->x; } } This would not yield an E_NOTICE because both isset() and empty() never do. This allows the attentive programmers to keep up there coding practices without the necessity to assign meaningless values everywhere. class A { /** -1 is invalid */ public int $x =3D -1; /** 'INVALID' is invalid but empty string is allowed */ public string $s =3D 'INVALID'; /** Null byte is invalid but anything else is valid */ public string $welcome_to_the_c_world =3D '\0'; } Not cool. :( --=20 Richard "Fleshgrinder" Fussenegger --8Q76XPPtMrV9DD7daoueXGE1s5IsMoMb5-- --llhltFwfIvMXDF9GrJvf4SNncPV6RdJsn Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJXRyjZAAoJEOKkKcqFPVVrN+wP/272nJM/lnxLZd1NQmC++fHS XWl4VtpkTe1KzejySaPn82mdw2/zoXwd8XFHXq+yDMutgAGFl5b2mCZWdrGHFV2M nMb1umIp1KloCERie+7LLbmMvemJZ8DF1gT8yOZKLX3XkFBwI4TFbr9ilw4jbRUp 5floEFggDSfHh3fP+MmK54rhzqE1xoQS+QOJqz+KS682ASvvXlEbl1za2MukXSKT 9y4C7WPUnoB/a26Z5VkVNprRw/1rIJ+oG4R7PXoa7UTC2ucV8DL6YmQQgbtlt1Zw gBMfCIWDo++Ev1Te5dqJcnw6UpLsDnxR8k6N/3NLtW740aXiqdyhPTlQxdnbCAwz 4FttwQjrf9SF/6kOIeCsJWzO17wfkTeSYxOf5FXYBZG3+miQE7AsPa09FiHyjkFw +9ed9l8VL1r8nhxlFpie9kaE+aNo7FnSdGwWSG4XxhTkgng5U2H6NVlCobVvk5fx VAdVCNpdqu4cJZHlNrjp3GZoxc6CpQws0Kz/rDR9weCoAocNoIy3p2YORaoFRY8b HfOJr9SXmzIBFWCuCUJqk9Ypz9OeV3CGZQ6CVbMFWTccoL0oqpWVjVpKk8Gt0FKK 6PYRREU4nogl+xZ7PweprZgW2YBhqPBUhrY/5Rt9k8DVkwXu7eTv4hfB4NKoWhNF U3iO/6GtrH2nXfaiYmck =VBei -----END PGP SIGNATURE----- --llhltFwfIvMXDF9GrJvf4SNncPV6RdJsn--