Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63495 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17945 invoked from network); 17 Oct 2012 11:04:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2012 11:04:07 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:65222] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/97-64689-7A09E705 for ; Wed, 17 Oct 2012 07:04:07 -0400 Received: by mail-lb0-f170.google.com with SMTP id gm13so5107963lbb.29 for ; Wed, 17 Oct 2012 04:04:04 -0700 (PDT) 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=6R+KNlA7X293dM1nAWg0qYZf2xxiXKaYkAbihD87PgM=; b=qOEdooXwK+yXR6Teq4Rt/WVsqxndrMLt/l4IuIppn1Vtlz3UV92Zrtg3acEH/mTsB2 5f+7lt+zeJzxpAT9f/qoPv+tcgCUYw4qRsv6mz/BdVsGmBtaQ0w1VWgUUGeyJSItytfW +2253Gr+zVTCQXY+10OfkS6RiEuqRLMe+6QNWrBwegeDZisOAILqo93wZSBFqnkqIKWf 90YnnkYn3k4yMMoMFiMZrWnlLR+D5o3CoTCekEyknGx7Ef1aQHGmxSSx6KWoJg9BRkN5 5K6fwygPAuB1cdwoYy1mNi4cBXSqTVXWt2QHXyJRUzDvBFer2dNFKMRPVgRkviw69Vq9 RQdQ== MIME-Version: 1.0 Received: by 10.152.133.140 with SMTP id pc12mr15401967lab.53.1350471844437; Wed, 17 Oct 2012 04:04:04 -0700 (PDT) Received: by 10.112.83.100 with HTTP; Wed, 17 Oct 2012 04:04:04 -0700 (PDT) In-Reply-To: <507D3D29.9070709@sugarcrm.com> References: <9570D903A3BECE4092E924C2985CE485612B6434@MBX202.domain.local> <507D133A.4040701@sugarcrm.com> <507D2FB3.3030806@sugarcrm.com> <507D3D29.9070709@sugarcrm.com> Date: Wed, 17 Oct 2012 13:04:04 +0200 Message-ID: To: Stas Malyshev Cc: Amaury Bouchard , Levi Morrison , Clint Priest , "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [PHP-DEV [RFC] Property Accessors v1.2 : Typehints / Accessor Syntax From: nikita.ppv@gmail.com (Nikita Popov) On Tue, Oct 16, 2012 at 12:55 PM, Stas Malyshev wrote: >> Last thing: I agree with Clint and you. If it was early checked, it >> would be better. But the current type hinting is far better than nothing >> at all. Yes, we can't "lint" it, but it was pretty useful a big number > > No, it's not better. Having code that can randomly fail with one error > message is not better than having code that can randomly fail with > another error message. It is more or less the same. It actually makes a very big difference just how exactly the code fails. Whether it fails at the point where you assign an invalid value to a property or whether it fails 50 frames down the line where that property is then read and you don't really know where that value came from. The extreme example of just how much of a difference it can make is C++ template metaprogramming. If you ever used a heavily templated library in C++ you'll know the pain of looking at a 400 line long template trace and trying to figure just where you went wrong. It's obviously not that extreme in PHP, but it's always better to get a directly relevant error message, rather than the error popping up somewhere down the line (or if you're very unlucky not turning up at all). > It can actually be > worse since it'd introduce more boliterplate checks in wrong places > (i.e., you'd have to check every variable for correct type before > assigning it to typed property) I see this argument crop up with every typehint discussion and just don't understand it at all. Why would you want to check the variable type everywhere? You just assign it and if it doesn't work, then you get an error. Just like it should be. I mean, do you seriously check the type of every function argument because you fear the parameter type hints that much? Doesn't make sense to me. > and does not provide any control over > how the situation when something is wrong is going to be handled. That's not related to typehints really. PHP just does not have a usable mechanism for recovering from error situations. You can register an E_RECOVERABLE error handler and let the code continue, but it's all very inconvenient. Also, I never had a situation where I wanted to recover from a failed parameter type check. I don't see how property type checks are different.