Re: [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters

From: Date: Sat, 10 Mar 2012 03:32:41 +0000
Subject: Re: [POC - Patch] Scalar Type Hinting - A-La zend_parse_parameters
References: 1 2 3 4 5 6  Groups: php.internals 
Request: Send a blank email to internals+get-58828@lists.php.net to get a copy of this message
Lazare, >> This won't make it easy passing a variable as reference. > > Type casting combined with passing by reference is problematic in many ways. No it's not. The core functionality does it quite fine, and it uses typed parameters... > 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. This one one where my wants are superseded by existing functionality. The current implementation has a definite answer to that. And the answer is that no, no notice is raised. Plenty of people are using it to that effect right now. Check out this abomination: http://stackoverflow.com/questions/9636052/is-there-a-way-to-pass-an-undeclared-variable-to-a-function-without-notice/9636395#9636395 However, it's also quite useful. Look at your code base. Whenever you call preg_match with the third parameter, do you *always* initialize the $match parameter? And do you *always* make sure it's an array? The chances are very likely (based on a lot of the code I've seen), no. This functionality is very pervasive to the core, and we shouldn't go changing it now (even implementing user-land pass-by-reference). Not supporting references is one thing, but changing the semantics of it is a completely different talk... Anthony

« previous php.internals (#58828) next »