On 27/05/16 09:27, Rowan Collins wrote: >>>>> // accessing $me->marriage or $me->death returns NULL (because they >>>>>> allow nulls) but raises E_NOTICE >>>> BUT DateTime currently will not store 'null' - it returns 'now' >>>> instead. >>>> We end up having to store string or integer values because we can't >>>> store a null date :( >>> >>> That's exactly what ?DateTime is for - "either DateTime or Null", just >>> like in a database. >>> >>> In most type systems, there is no such thing as "a null date" - if it's >>> null, it's not a date, it's a null value. >> >> The exact question here then is in relation to just how one uses >> 'DateTime' in this situation? Or more accurately how one maintains the >> 'or Null' state when the type does not allow null itself? > > I don't understand the question. > > class Foo { ?DateTime $d } > $f = new Foo; > $f->d = null; > $f->d = new DateTime; > > It's either a DateTime, or it's null.
Now I am confused, but it's probably because I'm looking at a simple $f->d = new DateTime( $initial ); While you are looking at If ( isset($initial) ) then $f->d = new DateTime( $initial ); else $f->d = null; While the original code would have simply been $f->d = $initial; 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 do all of the checks on that are provided by int or DateTime as appropriate ... 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? -- 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