On Nov 24, 2010, at 14:02, Stas Malyshev wrote:
>> 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:
> 
> I think there's something wrong with it, primarily - the fact that it doesn't 
> really make any sense. The object/null thing is a kludge. Unfortunately, I 
> don't see a proper way to handle this without named arguments.


Ok, I re-wrote the patch and test:
http://bugs.php.net/patch-display.php?bug_id=53399&patch=strict-required-opt2.patch&revision=latest

Now, the test happens in zend_do_end_function_declaration(). It loops through 
each of the function's parameters and emits the E_STRICT if it detects a 
required parameter after an optional parameter. The tests are loosened so that 
Class $param = null will not by itself trigger the warning. So it's not a 100% 
solution since we have to allow for the object/null kludge, but it's still an 
improvement from not having anything at all.

To make this work, I added a field to zend_arg_info, 'optional', which is 
populated in zend_do_receive_arg(). Also, we might want to modify 
php_reflection.c:_parameter_string() to use zend_arg_info.optional, which would 
allow indicating whether the parameter was declared optional vs. whether it 
actually is being treated as optional.

I think I can move the implementation back into zend_do_receive_arg(), but 
before I go ahead and do that, I'd like to make sure everyone's happier with 
this solution than my first. It might also be possible to get rid of 
zend_arg_info.optional, but I'd need to know how/if it's possible to access the 
relevant oplines for the rest of the function's parameters.

-John

--
John Bafford
http://bafford.com/


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

Reply via email to