Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93605 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78719 invoked from network); 27 May 2016 10:26:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 May 2016 10:26:10 -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 77.244.243.86 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.86 mx105.easyname.com Received: from [77.244.243.86] ([77.244.243.86:34288] helo=mx207.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1E/F6-37127-1C028475 for ; Fri, 27 May 2016 06:26:10 -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 1b6Exy-0002Oj-Au; Fri, 27 May 2016 10:26:06 +0000 Reply-To: internals@lists.php.net References: <20160525215208.034FC1A801B3@dd1730.kasserver.com> <5fd54aa0-4fdf-c1e7-eae8-765aa89c8498@fleshgrinder.com> <08963b03-8394-6d62-4e5b-393f3fcb5647@fleshgrinder.com> <9e9db70d-d72d-d93e-0c81-18c2aa228618@gmail.com> <409002d8-b5e3-5990-7358-246adc7e3cab@fleshgrinder.com> <57474A08.80807@lsces.co.uk> <6f7403b6-bf22-a12b-dfb2-43fe82983e7d@fleshgrinder.com> <57474F9C.6080104@lsces.co.uk> <1733cfce-001b-1079-e929-88f7dde0f2dd@gmail.com> <57475F27.3090306@lsces.co.uk> <34edcbd1-2d6a-cd52-7bbb-c393ab62d32d@gmail.com> <574772BA.3030305@lsces.co.uk> <5748164C.7020803@lsces.co.uk> To: Lester Caine , internals@lists.php.net, Rowan Collins Message-ID: <5156d2d3-6c7b-b5d0-fdfd-9064d8fb1d58@fleshgrinder.com> Date: Fri, 27 May 2016 12:25:48 +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: <5748164C.7020803@lsces.co.uk> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="6wLKrjmmsBGm4FqKS7X3bjLHqCcn3kfp5" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: php@fleshgrinder.com (Fleshgrinder) --6wLKrjmmsBGm4FqKS7X3bjLHqCcn3kfp5 Content-Type: multipart/mixed; boundary="f782XpGkJR94HJ1jMhiaEWbvoxEgXATtT" From: Fleshgrinder Reply-To: internals@lists.php.net To: Lester Caine , internals@lists.php.net, Rowan Collins Message-ID: <5156d2d3-6c7b-b5d0-fdfd-9064d8fb1d58@fleshgrinder.com> Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties References: <20160525215208.034FC1A801B3@dd1730.kasserver.com> <5fd54aa0-4fdf-c1e7-eae8-765aa89c8498@fleshgrinder.com> <08963b03-8394-6d62-4e5b-393f3fcb5647@fleshgrinder.com> <9e9db70d-d72d-d93e-0c81-18c2aa228618@gmail.com> <409002d8-b5e3-5990-7358-246adc7e3cab@fleshgrinder.com> <57474A08.80807@lsces.co.uk> <6f7403b6-bf22-a12b-dfb2-43fe82983e7d@fleshgrinder.com> <57474F9C.6080104@lsces.co.uk> <1733cfce-001b-1079-e929-88f7dde0f2dd@gmail.com> <57475F27.3090306@lsces.co.uk> <34edcbd1-2d6a-cd52-7bbb-c393ab62d32d@gmail.com> <574772BA.3030305@lsces.co.uk> <5748164C.7020803@lsces.co.uk> In-Reply-To: <5748164C.7020803@lsces.co.uk> --f782XpGkJR94HJ1jMhiaEWbvoxEgXATtT Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 5/27/2016 11:41 AM, Lester Caine wrote: > Now I am confused, but it's probably because I'm looking at a simple >=20 > $f->d =3D new DateTime( $initial ); >=20 > While you are looking at >=20 > If ( isset($initial) ) > then $f->d =3D new DateTime( $initial ); > else $f->d =3D null; >=20 > While the original code would have simply been >=20 > $f->d =3D $initial; >=20 > And in an ideal world, because $d has been typed as DateTime this would= > magically run 'new DateTime($initial)' which is where I am stumbling > because *I* simply look at '?DateTime $d' as creating a DateTime object= > where in fact $d is a different type of object which will then hold the= > link to the real one. I am still looking for $d to be an object I can d= o > all of the checks on that are provided by int or DateTime as appropriat= e > ... the object needs to exist before the 'new' in order to know if you > need the first or second type of $initial code ... or we make typed > properties only work one way or the other? >=20 PHP does not automagically instantiate the DateTime object for you, this is still your responsibility. The type hint on the property only restricts what you are allowed to assign to the property, nothing else. It is true that PHP will coerce the value automatically if you are in weak mode but this is only true for scalar values and nothing else. Also note that you might not want that while working with a database because PHP might destroy your UNSIGNED BIGINTs without you noticing. class O { public ?DateTime $d; } if (isset($row['d'])) { $o->d =3D new DateTime($row['d']); } No need to assign null since it already is null by default and the nullable hint will not result in any errors upon accessing it. PS: The UNSIGNED BIGINT thing is one of the reasons why I want intersection and union types so that we can do the following: class O { private int|string $id; } And leave it to a more intelligent system to determine whether this can be safely converted to an int or not (e.g. MySQLi). --=20 Richard "Fleshgrinder" Fussenegger --f782XpGkJR94HJ1jMhiaEWbvoxEgXATtT-- --6wLKrjmmsBGm4FqKS7X3bjLHqCcn3kfp5 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 iQIcBAEBCAAGBQJXSCCvAAoJEOKkKcqFPVVrhvgP/iQpLwFJCE4vR6nBk/RnDOEW uoCIZ8Nb54GCdyh1bS2O7R84VEfsF0C9T2uKuJ67L7LDcXVsUFvIlx3mjcKZnAx+ IMBq10gRvjP1zBVkfRrsMLThH/ljLBZE+6fK2VcehAGLmZIlR1WyCLyA6EzEMzld 0hZnNqScSzcmmjekUnwzyhCoL3aT8vw8SxebUkz3e+AccpRmA6iWcPOfhXpt7GKG CErm9Fz4QFYrGlU+MqeTrlniCclGB1ouskBw9JOA4icRqB7pMRwFXH2OrKFEOSMQ CcJDTtundgr1bLxLZ+gDzbGtnmYBRutGsaCZ6nE59i2EjsqTsOc5Dn3AfG8WjN6T MuftNRMYXLt+aSpkewivmANOY2cYoYyYFC2nBfxlQifMok213a8iHA+M+Ntr8L4L I+2hXXg4aIS33toxtun6sK2n/zf/pd2wIUAXyp9gVYAG//m+BRi/Nw3whJ0ae9bh GuWNFFTGHfmS1iRQsDHdD+ubnWWeDD3K8aVspmwf7BKsQnwlOTdESiGeQxRFDs3w IADHIpqD4xx4zalpYUQSzzsmSlSQC1NvQEQMkv30wJKY/LC5hD+HQSOPWyIypdAz kdQaredeV5FFc6wda0QsXtvaIBJ9Wi790FK7Z9/BJNsORj+P8c2pHm8cutWGcASX +WL9TG2e9d86EIaX6qZu =8cOl -----END PGP SIGNATURE----- --6wLKrjmmsBGm4FqKS7X3bjLHqCcn3kfp5--