On 26/05/16 18:26, Fleshgrinder wrote: > 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.
DateTime is probably a better example to work with than 'int' since it already has a long pedigree of problems and clashes where many projects had their own interpretation and still use their own version of the class. My problem with '\DateTime $d' is that by default it returns 'now' rather than an 'empty/null' value in which to put the data from the database. I can't create a 'null' version of DateTime so one has to have a phantom date simply to ensure you know if it has been initialized with your own data later - or continue to use the older user space classes. It is handling just how the variable/property is initialized that is the whole problem here and there may be very good reasons that the initialization is later then the 'construct' be that a DateTime or an int ... null is the correct way of indicating that 'as yet we do not have the value of type xxx' just as it does for an untyped value, so trying to make a special case to block it's use is simply strangling normal usage in other cases? -- Lester Caine - G8HFL ----------------------------- Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php