Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:58827 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58622 invoked from network); 9 Mar 2012 23:32:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Mar 2012 23:32:33 -0000 Authentication-Results: pb1.pair.com header.from=linepogl@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=linepogl@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.170 as permitted sender) X-PHP-List-Original-Sender: linepogl@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-gx0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:39517] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 93/52-39571-0139A5F4 for ; Fri, 09 Mar 2012 18:32:32 -0500 Received: by ggmb2 with SMTP id b2so1477462ggm.29 for ; Fri, 09 Mar 2012 15:32:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=0vLpxxiyyDyxSxdpyFfsPScYhqcT0PAnnV63/OZDfNE=; b=TzFBKCsixCElzieP5ATRMzwWCrmRFbHbah8kvTZW725cZ/Zco3vYRpABYh/lhC0HvV yT5I8lA3RfuFgCcG5qnbkCiOWtfyZQCbaiLpFm87Ne3RjBYFYSgClq+w3rDPTHQn9zvJ 2s35IczJcLk+R20Xi51E5HEHI4CgZTOko0iE5ZGIeF3mge6HyRFg6mm6V0CnhKrKX4p3 aDnaW74XrGjDmsHJLWfyxw/GaZmlbTdB3uOzpXhlhBR9i6GrQmzUxN0GYzHWO9QkdJ2k 6zVX2tZ/e5d/qepC1gz5RAWCTdEqFFeeH9Tu6aZFEaFZQNG0T6M2epDZPm2HkNiKWigy qSUA== Received: by 10.101.4.15 with SMTP id g15mr1483991ani.85.1331335950266; Fri, 09 Mar 2012 15:32:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.146.144.35 with HTTP; Fri, 9 Mar 2012 15:32:10 -0800 (PST) In-Reply-To: References: Date: Sat, 10 Mar 2012 00:32:10 +0100 Message-ID: To: John Crenshaw Cc: Simon Schick , Anthony Ferrara , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001636c5bfd464739c04bad7ce7c Subject: Re: [PHP-DEV] [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters From: linepogl@gmail.com (Lazare Inepologlou) --001636c5bfd464739c04bad7ce7c Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable > what if we added extra out and inout hints for references? With the danger of becoming boring, I have to say that C# also support "ref" and "out" arguments... Are we reinventing the wheel here? To be honest, this is going too far. Can we have the basics first? Passing by reference is a corner case, at least for PHP. Lazare INEPOLOGLOU Ing=C3=A9nieur Logiciel 2012/3/9 John Crenshaw > From: Simon Schick [mailto:simonsimcity@googlemail.com] > > > > 2012/3/9 Lazare Inepologlou > > > > > > Type casting combined with passing by reference is problematic in man= y > ways. Just an example: > > > > > > fuction foo( string & $buffer) { ... } foo( $my_buffer ); > > > > > > Here, $my_buffer has just been declared, so it is null. Should this b= e > an error? I don't know! So, I think that that passing by reference should > not be (immediately) supported. > > > > > > > Hi, Lazare > > > > This should at least throw an E_NOTICE :) And also an error as NULL is > not allowed here. > > > > Let me modify your example: > > > > fuction foo( string & $buffer =3D NULL) { ... } foo( $my_buffer ); > > > > This would only raise the E_NOTICE because the variable has not been > declared. > > Or would you say that NULL is equal with an empty string (talking about > implicit casting)? I would not like that, but if, don't let it be (int)0 = or > (bool)false as well. > > > > Bye > > Simon > > 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 suppos= ed > to contain an input (even though that would be against all sane rules mos= t > of the time). > > 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 =3D NULL) { ... } foo( $my_buffer ); > > // In any case no errors on these: > fuction foo( inout string & $buffer =3D NULL) { ... } foo( > (string)$my_buffer ); > fuction foo( string & $buffer =3D NULL) { ... } foo( (string)$my_buffer )= ; > > 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. > > Like I said, no attachment to this at all. My gut tells me I may have > missed something really stupid here. Just brainstorming. > > John Crenshaw > Priacta, Inc. > --001636c5bfd464739c04bad7ce7c--