Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93602 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72321 invoked from network); 27 May 2016 09:41:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 May 2016 09:41:36 -0000 Authentication-Results: pb1.pair.com header.from=lester@lsces.co.uk; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lester@lsces.co.uk; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain lsces.co.uk from 217.147.176.214 cause and error) X-PHP-List-Original-Sender: lester@lsces.co.uk X-Host-Fingerprint: 217.147.176.214 mail4-2.serversure.net Linux 2.6 Received: from [217.147.176.214] ([217.147.176.214:45980] helo=mail4.serversure.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9D/B5-37127-F4618475 for ; Fri, 27 May 2016 05:41:36 -0400 Received: (qmail 1572 invoked by uid 89); 27 May 2016 09:41:33 -0000 Received: by simscan 1.3.1 ppid: 1565, pid: 1568, t: 0.0873s scanners: attach: 1.3.1 clamav: 0.96/m:52/d:10677 Received: from unknown (HELO ?10.0.0.7?) (lester@rainbowdigitalmedia.org.uk@81.138.11.136) by mail4.serversure.net with ESMTPA; 27 May 2016 09:41:32 -0000 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> Message-ID: <5748164C.7020803@lsces.co.uk> Date: Fri, 27 May 2016 10:41:32 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: lester@lsces.co.uk (Lester Caine) 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