2

I noticed that in 95% of cases there is always just return; after evaluating zend_parse_parameters to FAILURE inside PHP_FUNCTION. It did not make sense because PHP_FUNCTION are expected to return ZVAL. I am not sure what default value of return_value is when it is not explicitly set.

I searched through all php sources and all extension sources that came bundled with php. In 95% of cases they simply used return. In few extensions - date and intl they do RETURN_FALSE. In an article written by Sara Colemon she used RETURN_NULL().

I feel strongly that I should be using RETURN_FALSE for most cases which make more sense for PHP_FUNCTIONs. Am I missing something somewhere?

0

1 Answer 1

1

If zend_parse_parameters() fails, it is customary to simply return. That is documented in the PHP manual:

If zend_parse_parameters does not recieve what is specified by the Hacker as the correct arguments, and the arguments recieved cannot be converted to conform with type_spec an error will be raised, and by convention, the Hacker should return immediately.

According to the PHP manual, the type of return_value defaults to IS_NULL:

Pointer to a PHP variable that can be filled with the return value passed to the user. The default type is IS_NULL.

Furthermore, the PHP manual notes:

If the parameters given to a function are not what it expects, such as passing an array where a string is expected, the return value of the function is undefined. In this case it will likely return NULL but this is just a convention, and cannot be relied upon.

So the actual return value in case of failing zend_parse_parameters() has to be regarded as implementation detail, and consequently, simply returning appears to be most appropriate – just let the Zend engine decide about the default.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.