Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64584 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 47527 invoked from network); 6 Jan 2013 00:25:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2013 00:25:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.179 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.220.179 mail-vc0-f179.google.com Received: from [209.85.220.179] ([209.85.220.179:47775] helo=mail-vc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/80-62408-194C8E05 for ; Sat, 05 Jan 2013 19:25:55 -0500 Received: by mail-vc0-f179.google.com with SMTP id p1so18204769vcq.10 for ; Sat, 05 Jan 2013 16:25:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=fhogup97NBYkrCWZETZPvhh8Ks09hMovCWzaQIqPm94=; b=RwgznZPyqfBkyhmeuS+K7agX69/v1mt8+4V+MBTY9dSAd0lAr9Cawrdoyk9X65mjz+ B1gOLSx05C1OMtYILKfx8G9JVX/WjVkf/L9WDqzbP0ilZx1VcUMborm4rlXmDqz2N18a DLVzD7e/GsRjpovdH16idVS2JqQybSBj0ZjXAPwGBU2ExZEQUZrcGDKem+UGFcD+lnMI J+KsU1MUsQ5XNcr+thNfLnVh3kk6xtax1tPzO/Gh+LVioYkTGzUWWPf3BXlO3zIBsmQt LKFGuXWnYXuk12rqMGOVhbbrtBfYwjYjKUG++kNPpojg8OsPeAUFeLAiFtJRKvMLdfqC s3Tg== MIME-Version: 1.0 Received: by 10.52.16.17 with SMTP id b17mr69626687vdd.86.1357431950694; Sat, 05 Jan 2013 16:25:50 -0800 (PST) Received: by 10.58.56.137 with HTTP; Sat, 5 Jan 2013 16:25:50 -0800 (PST) In-Reply-To: <50E8C2BA.9080309@sugarcrm.com> References: <19D80B01-BE88-4119-8A15-B631A96060E5@mrclay.org> <50E8AA4D.5090207@sugarcrm.com> <50E8C2BA.9080309@sugarcrm.com> Date: Sat, 5 Jan 2013 19:25:50 -0500 Message-ID: To: Stas Malyshev Cc: Nikita Popov , PHP internals Content-Type: multipart/alternative; boundary=bcaec50408e83a5a1904d293c16c Subject: Re: [PHP-DEV] [RFC] Alternative typehinting syntax for accessors From: ircmaxell@gmail.com (Anthony Ferrara) --bcaec50408e83a5a1904d293c16c Content-Type: text/plain; charset=ISO-8859-1 Stas, But this in for methods, and you are putting it into entirely different > place - property initializer. That's what I call magic - somehow > property initializer magically becomes method parameter's default value. The same could be used to justify the param order difference between strings and arrays "But these are arrays, they are entirely different"... > > This becomes especially true if initializers are added, where the > > property would be initialized to a non-null value. Hence adding the > > ability for it to *never* actually *be* null in the first place... > > I think property initializers won't work well, especially combined with > this syntax. What should public DateTime $foo = 42; produce? > A compile time fatal error. If it's typed, the only values allowed are the type and null (in the initializer) > Essentially it looks like the only initializer useful here would be > NULL. In this case, why not just make it simple and always allow NULL > there and get rid of the confusing syntax? You'd have to allow NULL > anyway since otherwise you'd be unable to implement unset() and won't > have any useful isset(). In fact, initial value of any object property > will always be NULL, so not allowing NULL is pointless as there's always > NULL there when you start. > 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(); } } } As far as "why not just make it always allow null" is that it half defeats the point of typed accessors in the first place. Java has huge issues with 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 place. Sure, there are going to be use-cases for supporting null. But there are also plenty of use-cases for explicitly Not allowing null. In fact, I'd argue that the "not allow null" use-cases are the most frequent and most critical ones... Anthony --bcaec50408e83a5a1904d293c16c--