Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93584 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95523 invoked from network); 26 May 2016 19:56:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 May 2016 19:56:47 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-wm0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:36090] helo=mail-wm0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 93/8E-17600-EF457475 for ; Thu, 26 May 2016 15:56:47 -0400 Received: by mail-wm0-f54.google.com with SMTP id n129so242652209wmn.1 for ; Thu, 26 May 2016 12:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=BVOyenRGhVCFPHscF6663WskWCnnFJ6sb2DFYIIVimg=; b=psLLHbDkfmvmPkErDxTWj4RI6NIOFIww+7EZMtgP6iisQATUVfqOI5DYZ7w3lDqg3K s3NTr5nrE+vHtk+541O0B1RRYdddKesrC+CNuRyOXZ1egGXLjYtd6MaSaZYqgXHyjppP qJ8JrUZXhkgHolV5Q0qhK0kjVe50uJSpaaWe5neaN0ENKj9sZQidQe7JLwCZVGw30PW7 G8RBmOAZG1sD6BJ31Ks1uoVkA1XwuNlKIEstDCmFXV/iM/K5lPCrRt2cPZZ/O5jb4jKX IurIx8F1PWMnD+cWNCmybl9Kr62G7s6QPw3bbSEYreNGRMX0Josf5cuZ59uphTL6r39A PxXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=BVOyenRGhVCFPHscF6663WskWCnnFJ6sb2DFYIIVimg=; b=NipUKwFKbqcMc51l0+JDzTAs7nc2zYrFj1lnx6QjtJJUlvW+c5boEyZKmJdP7Cykrt iiDn+QFW+IFQcx7BPmmXffkSBDLo3zEkOnDKWYvwIl6HaL19sOP5n+qjhraYTXopcsHW q1RNX+1W8b4YTRxCD8bm0rBp3KfKhX6Cej0z2b5+TrMDeokJWxp80thKOGJTP82leMt2 D89B0gAhx5XbSAs1AYsmKR5gdo0gJ86FIZUJOfAjRD/3Hv4NFRI38nCsF4/bjVhYRoGX R9glyEClJkGnlMOMRF7IkPvI+Nu1Gd0T+x/aFTUr/5VXlOuxBAUTbuhVrA6e+24BvbzH +/bQ== X-Gm-Message-State: ALyK8tKNgMuJp82HNS9q1GEYxsHDUgWzuy6SOGzN2/y7e3veSt03O3qzWt4lG5NVPkol0A== X-Received: by 10.28.56.132 with SMTP id f126mr5188658wma.96.1464292603784; Thu, 26 May 2016 12:56:43 -0700 (PDT) Received: from [192.168.1.5] ([2.25.96.65]) by smtp.googlemail.com with ESMTPSA id t3sm5016742wmf.20.2016.05.26.12.56.42 for (version=TLSv1/SSLv3 cipher=OTHER); Thu, 26 May 2016 12:56:43 -0700 (PDT) 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> Message-ID: <1733cfce-001b-1079-e929-88f7dde0f2dd@gmail.com> Date: Thu, 26 May 2016 20:56:35 +0100 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: <57474F9C.6080104@lsces.co.uk> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC][Vote] Typed Properties From: rowan.collins@gmail.com (Rowan Collins) On 26/05/2016 20:33, Lester Caine wrote: > If I am creating an object which is a 'person' for which I actually want > to ensure I have valid dates for birth, marriage and death and an > integer 'no of siblings' then I have a set of 'typed' properties. > Initially the object is not initialized ... no person found in the > database ... so null values for every property in the object. When I > search and find a match, then I may get someone who is 'alive' so the > death property remains null. Currently one can not use DateTime > variables to do any of this as they have already defined their own > alternative to null by blocking it. So in this case it is pointless > trying to create any 'can be null' flag? Class variables are simply not > handling the problem consistently so one has to jump through hoops to > get back what used to be a simple null initialised set of properties? The current proposal (or the one which I am advocating) for that is that you would have something like the following: class Person { public \DateTime $birth; public ?\DateTime $marriage; public ?\DateTime $death; public int $numSiblings; } Creating an object would leave it in an invalid state: $me = new Person; // accessing $me->birth or $me->numSiblings is an error in this state, because defaulting to NULL would violate their type constraint // accessing $me->marriage or $me->death returns NULL (because they allow nulls) but raises E_NOTICE Now you can initialise the mandatory fields: $me->birth = new \DateTime($db_record['birth_date']); $me->marriage = new \DateTime($db_record['marriage_date']); $me->death = new \DateTime($db_record['death_date']); $me->numSiblings = $db_record['num_siblings']; // all properties can now be safely accessed // $me->marriage and $me->death may still be null, as indicated by the "?" in their type spec // $me->birth is guaranteed to be a \DateTime object Regards, -- Rowan Collins [IMSoP]