Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64591 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 60502 invoked from network); 6 Jan 2013 01:43:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2013 01:43:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=steve@mrclay.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=steve@mrclay.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mrclay.org from 50.22.11.19 cause and error) X-PHP-List-Original-Sender: steve@mrclay.org X-Host-Fingerprint: 50.22.11.19 bedford.accountservergroup.com Linux 2.6 Received: from [50.22.11.19] ([50.22.11.19:34886] helo=bedford.accountservergroup.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 30/F2-62408-3D6D8E05 for ; Sat, 05 Jan 2013 20:43:48 -0500 Received: from ip68-101-74-66.ga.at.cox.net ([68.101.74.66]:54177 helo=[192.168.11.20]) by bedford.accountservergroup.com with esmtpsa (TLSv1:DHE-RSA-AES256-SHA:256) (Exim 4.80) (envelope-from ) id 1TrfH6-000BGb-L9 for internals@lists.php.net; Sat, 05 Jan 2013 19:43:44 -0600 Message-ID: <50E8D6D0.7030307@mrclay.org> Date: Sat, 05 Jan 2013 20:43:44 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:17.0) Gecko/17.0 Thunderbird/17.0 MIME-Version: 1.0 To: internals@lists.php.net References: <19D80B01-BE88-4119-8A15-B631A96060E5@mrclay.org> <50E8AA4D.5090207@sugarcrm.com> <50E8C2BA.9080309@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - bedford.accountservergroup.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - mrclay.org Subject: Re: [PHP-DEV] [RFC] Alternative typehinting syntax for accessors From: steve@mrclay.org (Steve Clay) On 1/5/13 7:25 PM, Anthony Ferrara wrote: > No, the other initializer that would be useful is `new Foo`. Assigning a > default value is not an initializer. An initializer is something that's run > on object construction (and has been discussed in other threads): > > class Foo { > public DateTime $bar { > init: { $bar = new DateTime(); } > } > } I think property init() would enable two bad practices: 1. putting too much logic in a property (SRP) 2. building dependencies within the object instead of injecting them (the better way is what we already do: receive dependencies in the constructor and assign them to the properties) > null pointers. And if you set the property in the constructor (and it's > typed), you should never have the chance for it to be non-null, unless you > explicitly define it that way. Otherwise, you'd have to litter your code > with is_null checks... Which defeats the point of the syntax in the first Which is why I think the default setting signature should not have "= null". If someone wants to allow setting the property *back* to null, they could easily: public Foo $foo { get; set($value = null); } I agree with you that, in an ideal world, a property with a declared type would *never not have* that type, but I think a property init() would be a bad tradeoff to make that a reality. The class constructor is the best place to do this, and maybe this is why C# forces property storage to be in fields; you can set fields directly from the constructor without going through property setters. Steve Clay -- http://www.mrclay.org/