Skip to content

Function Arglist Consistency (Userland / Native) #1665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions Zend/tests/014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,24 @@ array(2) {
[1]=>
string(%d) "%s"
}

Warning: get_included_files() expects exactly 0 parameters, 2 given in %s on line %d
NULL
array(2) {
[0]=>
string(%d) "%s"
[1]=>
string(%d) "%s"
}

Warning: get_included_files() expects exactly 0 parameters, 1 given in %s on line %d
NULL
array(2) {
[0]=>
string(%d) "%s"
[1]=>
string(%d) "%s"
}
array(2) {
[0]=>
string(%d) "%s"
[1]=>
string(%d) "%s"
}
array(2) {
[0]=>
string(%d) "%s"
Expand Down
49 changes: 21 additions & 28 deletions Zend/tests/017.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ var_dump(get_loaded_extensions(true, true));

define("USER_CONSTANT", "test");

var_dump(get_defined_constants(true, true));
var_dump(gettype(get_defined_constants(true)));
var_dump(gettype(get_defined_constants()));
var_dump(count(get_defined_constants()));
var_dump(count(get_defined_constants(true, true)));

function test () {
}

var_dump(get_defined_functions(true));
var_dump(gettype(get_defined_functions()));
var_dump(count(get_defined_functions()));
var_dump(count(get_defined_functions(true)));

var_dump(get_declared_interfaces(true));
var_dump(gettype(get_declared_interfaces()));
var_dump(count(get_declared_interfaces()));
var_dump(count(get_declared_interfaces(true)));

var_dump(get_extension_funcs());
var_dump(get_extension_funcs(true));
Expand All @@ -45,42 +45,35 @@ var_dump(count(get_extension_funcs("zend")));
echo "Done\n";
?>
--EXPECTF--
Warning: get_resource_type() expects exactly 1 parameter, 0 given in %s on line %d
Warning: get_resource_type() expects exactly 1 parameter, 0 given in %s on line 3
NULL

Warning: get_resource_type() expects parameter 1 to be resource, string given in %s on line %d
Warning: get_resource_type() expects parameter 1 to be resource, string given in %s on line 4
NULL
string(6) "stream"
string(7) "Unknown"
string(5) "array"
string(%d) "stream"
string(%d) "Unknown"
string(%d) "array"
int(%d)
string(5) "array"
string(%d) "array"
int(%d)

Warning: get_loaded_extensions() expects at most 1 parameter, 2 given in %s on line %d
NULL

Warning: get_defined_constants() expects at most 1 parameter, 2 given in %s on line %d
NULL
string(5) "array"
string(5) "array"
array(0) {
}
string(%d) "array"
string(%d) "array"
int(%d)

Warning: get_defined_functions() expects exactly 0 parameters, 1 given in %s on line %d
NULL
string(5) "array"
int(%d)

Warning: get_declared_interfaces() expects exactly 0 parameters, 1 given in %s on line %d
NULL
string(5) "array"
string(%d) "array"
int(%d)
int(%d)
string(%d) "array"
int(%d)
int(%d)

Warning: get_extension_funcs() expects exactly 1 parameter, 0 given in %s on line %d
Warning: get_extension_funcs() expects exactly 1 parameter, 0 given in %s on line 34
NULL
bool(false)
string(5) "array"
string(%d) "array"
int(%d)
string(5) "array"
string(%d) "array"
int(%d)
Done
6 changes: 3 additions & 3 deletions Zend/tests/018.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ echo "Done\n";
Warning: constant() expects exactly 1 parameter, 0 given in %s on line %d
NULL

Warning: constant() expects exactly 1 parameter, 2 given in %s on line %d
Warning: constant(): Couldn't find constant in %s on line %d
NULL

Warning: constant(): Couldn't find constant in %s on line %d
NULL

Warning: constant() expects parameter 1 to be string, array given in %s on line %d
NULL
int(1)
string(4) "test"
int(%d)
string(%d) "test"
Done
4 changes: 2 additions & 2 deletions Zend/tests/020.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ foo(1,2);
echo "Done\n";
?>
--EXPECTF--
Warning: func_get_arg() expects exactly 1 parameter, 3 given in %s on line %d
NULL
Warning: func_get_arg(): Called from the global scope - no function context in %s on line %d
bool(false)

Warning: func_get_arg(): Called from the global scope - no function context in %s on line %d
bool(false)
Expand Down
3 changes: 0 additions & 3 deletions Zend/tests/closure_040.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ $cas = $a->getStaticIncrementor();

$ca->bindTo($a, array());
$ca->bindTo(array(), 'A');
$ca->bindTo($a, array(), "");
$ca->bindTo();
$cas->bindTo($a, 'A');

Expand All @@ -38,8 +37,6 @@ Warning: Class 'Array' not found in %s on line %d

Warning: Closure::bindTo() expects parameter 1 to be object, array given in %s on line 25

Warning: Closure::bindTo() expects at most 2 parameters, 3 given in %s on line %d

Warning: Closure::bindTo() expects at least 1 parameter, 0 given in %s on line %d

Warning: Cannot bind an instance to a static closure in %s on line %d
30 changes: 0 additions & 30 deletions Zend/tests/exception_010.phpt

This file was deleted.

2 changes: 1 addition & 1 deletion Zend/tests/exception_handler_004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ Warning: set_exception_handler() expects the argument (::) to be a valid callbac

Warning: set_exception_handler() expects exactly 1 parameter, 0 given in %s on line %d

Warning: set_exception_handler() expects exactly 1 parameter, 2 given in %s on line %d
Warning: set_exception_handler() expects the argument (foo) to be a valid callback in %s on line %d
Done
8 changes: 0 additions & 8 deletions Zend/tests/function_exists_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ echo "*** Testing function_exists() : error conditions ***\n";
$arg_0 = "ABC";
$extra_arg = 1;

echo "\nToo many arguments\n";
var_dump(function_exists($arg_0, $extra_arg));

echo "\nToo few arguments\n";
var_dump(function_exists());

Expand All @@ -23,11 +20,6 @@ var_dump(function_exists());
--EXPECTF--
*** Testing function_exists() : error conditions ***

Too many arguments

Warning: function_exists() expects exactly 1 parameter, 2 given in %s on line %d
NULL

Too few arguments

Warning: function_exists() expects exactly 1 parameter, 0 given in %s on line %d
Expand Down
29 changes: 0 additions & 29 deletions Zend/tests/get_defined_functions_error.phpt

This file was deleted.

12 changes: 6 additions & 6 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(int num_
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,
min_num_args == max_num_args ? "exactly" : "at least",
min_num_args,
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
num_args);
}
Expand Down Expand Up @@ -739,7 +739,7 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons
/* 'Z' iz not supported anymore and should be replaced with 'z' */
ZEND_ASSERT(c != 'Z');
default:
return "unknown";
return NULL;
}

*spec = spec_walk;
Expand Down Expand Up @@ -873,7 +873,7 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
max_num_args = -1;
}

if (num_args < min_num_args || (num_args > max_num_args && max_num_args >= 0)) {
if (num_args < min_num_args) {
if (!(flags & ZEND_PARSE_PARAMS_QUIET)) {
zend_function *active_function = EG(current_execute_data)->func;
const char *class_name = active_function->common.scope ? ZSTR_VAL(active_function->common.scope->name) : "";
Expand All @@ -882,8 +882,8 @@ static int zend_parse_va_args(int num_args, const char *type_spec, va_list *va,
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,
min_num_args == max_num_args ? "exactly" : "at least",
min_num_args,
(num_args < min_num_args ? min_num_args : max_num_args) == 1 ? "" : "s",
num_args);
}
Expand Down
7 changes: 2 additions & 5 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ ZEND_API int zend_copy_parameters_array(int param_count, zval *argument_array);
_zend_get_parameters_array_ex(param_count, argument_array)
#define zend_get_parameters_array_ex(param_count, argument_array) \
_zend_get_parameters_array_ex(param_count, argument_array)
#define zend_parse_parameters_none() \
(EXPECTED(ZEND_NUM_ARGS() == 0) ? SUCCESS : zend_parse_parameters(ZEND_NUM_ARGS(), ""))
#define zend_parse_parameters_none() SUCCESS

/* Parameter parsing API -- andrei */

Expand Down Expand Up @@ -726,9 +725,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_callback_error(int severity, in
((void)_optional); \
\
do { \
if (UNEXPECTED(_num_args < _min_num_args) || \
(UNEXPECTED(_num_args > _max_num_args) && \
EXPECTED(_max_num_args >= 0))) { \
if (UNEXPECTED(_num_args < _min_num_args)) { \
if (!(_flags & ZEND_PARSE_PARAMS_QUIET)) { \
zend_wrong_parameters_count_error(_num_args, _min_num_args, _max_num_args); \
} \
Expand Down