Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64585 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49894 invoked from network); 6 Jan 2013 00:41:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2013 00:41:39 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.53 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.53 mail-la0-f53.google.com Received: from [209.85.215.53] ([209.85.215.53:62672] helo=mail-la0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/E0-62408-148C8E05 for ; Sat, 05 Jan 2013 19:41:38 -0500 Received: by mail-la0-f53.google.com with SMTP id fn20so12332513lab.12 for ; Sat, 05 Jan 2013 16:41:34 -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=doVR2OKvPiN68GBBDTPHSi/klO8IPA/8bQWqWZ5H9ag=; b=XwMyrdi7t0iAX/VNy8nxcIy6edejS9XadcRKHLWXq+slQ2nmCrTXAbAbZ3P4/4uAfI VKRLdqL0hVmYzzTpnjzL30pVJohlU7kfpE5/zwjQLdXTjHT9akk/GNFXwZIIJyEB/6TP 8O6rZt/qg0JKYUoz4ZF1802g3udLWIxvxIcieqAXlq4u+jB+LRPaLVTIlagqBi03bM8n owORdKTbi7lirx4YpbbdZntQS19phpjW1O6f/Evh5POr1w2zgb1W2NiTcCHTHEvdhNUT ysrW78GI7pLcWIB1oufBj6wAxzsPYd3vCGvgVNdurq4qE4getdMchxsnEGq9c6kb5X1o 86Hw== MIME-Version: 1.0 Received: by 10.152.105.203 with SMTP id go11mr53744851lab.53.1357432894138; Sat, 05 Jan 2013 16:41:34 -0800 (PST) Received: by 10.112.4.168 with HTTP; Sat, 5 Jan 2013 16:41:34 -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: Sun, 6 Jan 2013 01:41:34 +0100 Message-ID: To: Stas Malyshev Cc: Anthony Ferrara , PHP internals Content-Type: multipart/alternative; boundary=f46d04083e33762a2004d293f97c Subject: Re: [PHP-DEV] [RFC] Alternative typehinting syntax for accessors From: nikita.ppv@gmail.com (Nikita Popov) --f46d04083e33762a2004d293f97c Content-Type: text/plain; charset=ISO-8859-1 On Sun, Jan 6, 2013 at 1:18 AM, Stas Malyshev wrote: > Hi! > > > "Too much magic"? It's completely consistent with how method parameters > > work now. In fact, I'd argue that introducing a new syntax for this > > would be inconsistent with the current paradigm. > > 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. > > > 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? > Consider the normal function typehints: `function foo(DateTime $foo = 42)`. Same problem, same solution. You can only assign "compatible" types. For object typehints NULL is the only compatible compile-time value. For array typehints arrays can be used as initializers. > 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? Again, same for function typehints. NULL is the only possible initializer there, too. But still we don't take that as a reason to always allow NULL for them. You'd have to allow NULL anyway since otherwise you'd be unable to > implement unset() and won't > have any useful isset(). Not every property needs the ability to be unset(). Not being able to unset it is a feature actually. It guarantees that it will always be available (after the initial set) and does not have to be checked. 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. > The timeframe in which it is NULL is usually contained to the constructor. --f46d04083e33762a2004d293f97c--