> 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énieur Logiciel 2012/3/9 John Crenshaw <johncrens...@priacta.com> > From: Simon Schick [mailto:simonsimc...@googlemail.com] > > > > 2012/3/9 Lazare Inepologlou <linep...@gmail.com> > > > > > > Type casting combined with passing by reference is problematic in many > ways. Just an example: > > > > > > fuction foo( string & $buffer) { ... } foo( $my_buffer ); > > > > > > Here, $my_buffer has just been declared, so it is null. Should this be > 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 = 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 supposed > to contain an input (even though that would be against all sane rules most > 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 = NULL) { ... } foo( $my_buffer ); > > // 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 ); > > 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. >