On Nov 24 12:28:38, John Bafford wrote:
> Hi,
> 
> I filed a bug report with an attached patch that adds an E_STRICT warning 
> when defining a function with a required parameter after an optional function 
> parameter, for example:
> 
> function foo($optional = 1, $required) {}
> 
> Although doing this works, code written like that is probably making a faulty 
> assumption somewhere, and emitting this error would help raise the quality of 
> php code.
> 
> The bug and patch are here: http://bugs.php.net/bug.php?id=53399
> 
> The patch applies against both the PHP 5.3 branch, and trunk. I'm not sure 
> I'd advocate including it in PHP 5.3, but I'd definitely like to see it in 
> 5.4. The patch also includes two tests, and fixes this problem in the 
> Zend/tests/call_user_func_005.phpt test, which is the only test I found that 
> fails as a result.
> 
> At some point in the future, I would like to make this a more severe error 
> than an E_STRICT, but I'd rather not immediately break code that (until now) 
> worked without warning.
> 
> Thoughts/comments?


Given the semantics of PHP arguments, there is "nothing wrong" with
defining a required argument after an optional one, and in some cases
it is required. Consider:

function foo(Plop $a, $b) {}

if you want to allow 'null' for $a as well, you have to write:

function foo(Plop $a = null, $b) {}

Best,


> 
> -John
> 
> --
> John Bafford
> http://bafford.com/
> 
> 
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
Etienne Kneuss
http://www.colder.ch

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to