Re: [RFC][Vote] Typed Properties

From: Date: Thu, 26 May 2016 17:26:56 +0000
Subject: Re: [RFC][Vote] Typed Properties
References: 1 2 3 4 5 6 7 8  Groups: php.internals 
Request: Send a blank email to internals+get-93580@lists.php.net to get a copy of this message
On 5/26/2016 7:20 PM, Rowan Collins wrote: > I think the difference is the emphasis of whose responsibility it is to > fix it: a TypeError confirms that the error is in the O class for > exposing an incorrectly typed property; a NullPointerException, as you > put it, makes it my fault for trusting the class. > > Or to put it a different way, is the error in the first arrow (accessing > "->d") or the second one (de-referencing "d->"). > > > At the end of the day, all the type notations being added to PHP are > just assertions anyway. So the same could be said of this: > > function foo(\DateTime $d) { > echo $d->format('Y-m-d H:i:s'); > } > foo(null); > > If this didn't throw an error at "foo(null)", it would throw an error at > "$d->format". > Yes, they are just assertions and design by contract and you make a very good point here for an actual error. I am convinced. ;) However, it should not throw an error for isset() and empty() to allow more special constructs. As we already have it in place everywhere with the two. -- Richard "Fleshgrinder" Fussenegger

Attachment: [application/pgp-signature] OpenPGP digital signature signature.asc
« previous php.internals (#93580) next »