Re: [RFC] Replace "Missing argument" warning with "Too few arguments" exception

From: Date: Thu, 02 Jun 2016 12:04:58 +0000
Subject: Re: [RFC] Replace "Missing argument" warning with "Too few arguments" exception
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-93716@lists.php.net to get a copy of this message
On 06/02/2016 02:42 PM, Benjamin Eberlei wrote:
On Wed, Jun 1, 2016 at 12:55 PM, Dmitry Stogov <dmitry@zend.com <mailto:dmitry@zend.com>> wrote:
    hi,
    Please take a look into the proposal.
    https://wiki.php.net/rfc/too_few_args
    The RFC is extremely simple (both proposal and implementation) and
    almost completely described by the email subject.
    I think, this mini-RFC doesn't need 2-weeks discussion period, so
    I'm going to start the vote on next week.
Quick question, I think the error message might be a little confusing asking for "exactly $n" parameters, because it could be a variadic function using func_get_args(), shouldn't the message be? throw Error("Too few arguments to function %s(), 0 passed in %s on line %d and at least %d expected") "exactly" is going to be used for functions without variadic arguments and arguments with default values.
In that cases PHP will write "at least". See the patch https://github.com/php/php-src/pull/1928/files#diff-3054389ad750ce9a9f5895cd6d27800fR4753 This is similar to other PHP error messages.
    zend_internal_type_error(ZEND_ARG_USES_STRICT_TYPES(), "%s%s%s() expects %s %d parameter%s, %d given",
        class_name, \
        class_name[0] ? "::" : "", \
        ZSTR_VAL(active_function->common.function_name),
        min_num_args == max_num_args ? "exactly" : num_args < min_num_args ? "at least" : "at most",
        num_args < min_num_args ? min_num_args : max_num_args,
        (num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
        num_args);
This only changes the case where the passed arguments are smaller than the required ones or not? This is acceptable BC, but passing more arguments should still not be an error. Of course.
Thanks. Dmitry.
    Thanks. Dmitry.


« previous php.internals (#93716) next »