Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64605 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17047 invoked from network); 6 Jan 2013 14:48:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2013 14:48:48 -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.50 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.50 mail-la0-f50.google.com Received: from [209.85.215.50] ([209.85.215.50:46586] helo=mail-la0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BD/41-04877-ECE89E05 for ; Sun, 06 Jan 2013 09:48:47 -0500 Received: by mail-la0-f50.google.com with SMTP id fs13so13222346lab.37 for ; Sun, 06 Jan 2013 06:48:43 -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=rk9SUzXqrHqmhkhwB3nTXa5U1228ePjbZqoXaYwZJoI=; b=M3Z5Cpo4ovcq87JMpqtCHI5X9je7UGbCV7uu2OBuiE13KkxYUs4k7iSzJoKNHJqExa og4XHuito0wc8WvGJkCzfdeLltr/ne3oK7LvuZyjjAKIQFDv/wge8yPYmgMKO4Dqb6Vl Xi+OcIcH+VmZURUHRrOPJ/2fSur1GmPj9vj2tNTaOzTYly3zLb7574+hr/+JJlFYp3Fh q4KQ9ghNvYD+CAMTt25GAMSmGJZNFoV0mxGTf5pF3lgI5fFY3zS/PmgJ+neuutsFCphL Oz50yw/1JowhGKWK7H1exphjUJdiUC8dxPL9Xji9F1tYepbv9SmH+s2VNYwYxz28U37j pF/Q== MIME-Version: 1.0 Received: by 10.112.87.40 with SMTP id u8mr23625109lbz.50.1357483723268; Sun, 06 Jan 2013 06:48:43 -0800 (PST) Received: by 10.112.4.168 with HTTP; Sun, 6 Jan 2013 06:48:43 -0800 (PST) In-Reply-To: <50E8DA99.1060604@sugarcrm.com> References: <19D80B01-BE88-4119-8A15-B631A96060E5@mrclay.org> <50E8AA4D.5090207@sugarcrm.com> <50E8C2BA.9080309@sugarcrm.com> <50E8CDC8.6080809@sugarcrm.com> <50E8DA99.1060604@sugarcrm.com> Date: Sun, 6 Jan 2013 15:48:43 +0100 Message-ID: To: Stas Malyshev Cc: Anthony Ferrara , PHP internals Content-Type: multipart/alternative; boundary=bcaec554df401d228404d29fcfec Subject: Re: [PHP-DEV] [RFC] Alternative typehinting syntax for accessors From: nikita.ppv@gmail.com (Nikita Popov) --bcaec554df401d228404d29fcfec Content-Type: text/plain; charset=ISO-8859-1 On Sun, Jan 6, 2013 at 2:59 AM, Stas Malyshev wrote: > This is pretty bad by itself. But the fact that everybody would be using > this feature in this way - since they would think "I don't need null > default, null is always the default and I'd initialize it in the ctor > anyway", not realizing that declaring "public DateTime $foo" blocks > unset - is even worse. At least with setter you need to explicitly > define typehinted setter - and there you have a place to think about it. > With "public DateTime $foo" 99% of people would never even remember to > think about it - until they'd start getting mysterious fatal errors on > unsets. That's why I think it makes it worse. > In this mail I'm only going to address the unset() concern. First of all it should be made clear that contrary to the impression that you conveyed unset() is a fallible operation. It absolutely is fallible, even when overloaded properties and offset (__unset/offsetUnset) are not involved. If I write `unset($foo[0])` then this is an operation that can throw a fatal error, for example when $foo is a string. Why does this throw a fatal error? Because a string offset can not be unset. It's an operation that does not make sense and so PHP throws an error. PHP could also just do nothing, leave the string intact and pretend the unset() was successful. But it doesn't do so and it's good that it doesn't do so. What we are talking about here is a similar situation. We are talking about a property where it does not make sense to unset it. The unset operation is not meaningful and as such shouldn't be allowed. It's as easy as that. That's the first point. The second point is that even *if* an issue existed here (which it does not) then you are presenting it in a *totally* disproportional matter. You make it seem like unset()ing properties is this super important operation that we do all the time and the world would collapse if it failed. That's not true. Unset() on object properties is only used *very* rarely. Symfony Standard (including Symfony, Doctrine, Twig, ...) has a total of !! 4 !! property unsets (compare this to their ~3800 accessor methods). The ZF2 has 8 property unsets of which only !! 3 !! are targeted at specific properties (the remaining 5 are on stdClass-like objects). Again, compare this to their ~4k accessor methods. In summary: a) Unset() is a fallible operation, it's okay if it throws an error if the unset is not reasonably possible. b) Even if you *don't* agree with this assessment it's quasi a non-issue as property unsets are incredibly rare. Dismissing a feature based on something like this is absolutely implausible. c) You can always allow unset() and NULL assignment by specifying it as the default value. Not hard to do *should* you once run into issues of this kind. Thanks, Nikita --bcaec554df401d228404d29fcfec--