Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58829 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72638 invoked from network); 10 Mar 2012 03:48:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Mar 2012 03:48:26 -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.213.42 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.213.42 mail-yw0-f42.google.com Received: from [209.85.213.42] ([209.85.213.42:44629] helo=mail-yw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/14-39571-80FCA5F4 for ; Fri, 09 Mar 2012 22:48:24 -0500 Received: by yhfq11 with SMTP id q11so1584757yhf.29 for ; Fri, 09 Mar 2012 19:48:20 -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=uMw5gJB2OVAIOZ/RT0vdHLPgu42KutMZKmn7wBx9vnQ=; b=AuyRFKzpgLFvRwl/ojbFEg2bdjyk9lzIzQEPWPVlgUD5TQOYQMGmUECxCvIYHSP1Ii uwMUZGnw5F9DAWAEuspcLGlzk/iLAhh+Dxqk65xlKmBVCOvmkFff3T2g4vlFFtOkT7ql SYEj87X8DaazeMt+E+0CYq7IF04kFvO0ndpVLep45Ex3OJx+D9UA4tQF+yIrL3A62rgD k+wXae6JZI1t+syrcqCr9FWhkz+ULN/fl2yPyESp8aViIW+EbpzqgS/G8h7g3VkDKP28 /O0/ADpk+XiBuTDXp1I6lME/owh7PtS4DeUwWDAyDo9FX7M1X2eUkLU05W5RbFbDCcVJ JFRg== MIME-Version: 1.0 Received: by 10.229.135.3 with SMTP id l3mr415086qct.45.1331351300606; Fri, 09 Mar 2012 19:48:20 -0800 (PST) Received: by 10.229.49.74 with HTTP; Fri, 9 Mar 2012 19:48:20 -0800 (PST) In-Reply-To: References: Date: Fri, 9 Mar 2012 22:48:20 -0500 Message-ID: To: John Crenshaw Cc: Simon Schick , Lazare Inepologlou , "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters From: ircmaxell@gmail.com (Anthony Ferrara) John, > The reason you have to validate the input type in this case is because even though it is a reference, we don't ACTALLY know that it isn't supposed to contain an input (even though that would be against all sane rules most of the time). Well, we don't know, but I'd argue do we really care? If they passed a different type that's going to get casted away, that's their problem. They passed it to the hint. Now, if you're talking about object cast sementics, that raises a whole different ballgame. That's something that we should consider... > I'm not attached to this idea at all, but I thought I'd throw it out and see if anyone can think of a problem with it; what if we added extra out and inout hints for references? > > // So this would give no error at all. Parameter is anticipated to be for output. Just silently change the type and don't warn on anything. > fuction foo( out string & $buffer) { ... } foo( $my_buffer ); > > // This WOULD give an error, because the parameter is also an input parameter: > fuction foo( inout string & $buffer = NULL) { ... } foo( $my_buffer ); Why would NULL give an error under any circumstance? You defaulted it to null. So why should passing a NULL parameter in its place be any different than not passing a first argument? In fact, erroring on that would greatly reduce utility, since what if I wanted to set the 2nd parameter only? I can no longer pass NULL (even though it's a valid default), and have to change the first parameter. Big regression if you ask me... > // In any case no errors on these: > fuction foo( inout string & $buffer = NULL) { ... } foo( (string)$my_buffer ); > fuction foo( string & $buffer = NULL) { ... } foo( (string)$my_buffer ); Actually, these SHOULD cause errors (and do). Because they will not do what you expect. The cast causes a *temporary* variable to be created in opcode. And you can't pass a temporary variable by reference: http://codepad.viper-7.com/wLBSkS > If we assumed that all references were out unless stated otherwise we could avoid reserving an "out" keyword, and only add "inout", which is unlikely to conflict with stuff. I still fail to see the purpose. Both will cause a cast (since the value required on the other end needs to be initialized to the proper type). The only difference is that one throws an error on invalid cast, and the other doesn't. Seems to be to just be un-necessary added complexity (but feel free to convince me otherwise, I love to be convinced wrong)... > Like I said, no attachment to this at all. My gut tells me I may have missed something really stupid here. Just brainstorming. Oh absolutely. And brainstoring is good! Thanks, Anthony