Skip to content

Annotate internal functions with mixed type #5618

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 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions Zend/zend_builtin_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,13 @@ function trigger_error(string $message, int $error_type = E_USER_NOTICE): bool {
/** @alias trigger_error */
function user_error(string $message, int $error_type = E_USER_NOTICE): bool {}

function set_error_handler($error_handler, int $error_types = E_ALL): ?callable {}
/** @return string|array|object|null */
function set_error_handler($error_handler, int $error_types = E_ALL) {}

function restore_error_handler(): bool {}

function set_exception_handler($exception_handler): ?callable {}
/** @return string|array|object|null */
function set_exception_handler($exception_handler) {}

function restore_exception_handler(): bool {}

Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_builtin_functions_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_func_num_args, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_func_get_arg, 0, 1, IS_MIXED, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_func_get_arg, 0, 1, IS_MIXED, 1)
ZEND_ARG_TYPE_INFO(0, arg_num, IS_LONG, 0)
ZEND_END_ARG_INFO()

Expand Down Expand Up @@ -125,15 +125,15 @@ ZEND_END_ARG_INFO()

#define arginfo_user_error arginfo_trigger_error

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_error_handler, 0, 1, IS_CALLABLE, 1)
ZEND_BEGIN_ARG_INFO_EX(arginfo_set_error_handler, 0, 0, 1)
ZEND_ARG_INFO(0, error_handler)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, error_types, IS_LONG, 0, "E_ALL")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_restore_error_handler, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_exception_handler, 0, 1, IS_CALLABLE, 1)
ZEND_BEGIN_ARG_INFO_EX(arginfo_set_exception_handler, 0, 0, 1)
ZEND_ARG_INFO(0, exception_handler)
ZEND_END_ARG_INFO()

Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_closures_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Closure_bindTo, 0, 1, Closu
ZEND_ARG_INFO(0, newscope)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Closure_call, 0, 1, IS_MIXED, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Closure_call, 0, 1, IS_MIXED, 1)
ZEND_ARG_TYPE_INFO(0, newthis, IS_OBJECT, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, parameters, IS_MIXED, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, parameters, IS_MIXED, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Closure_fromCallable, 0, 1, Closure, 0)
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_generators_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_valid, 0, 0, _IS_BOOL, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_current, 0, 0, IS_MIXED, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_current, 0, 0, IS_MIXED, 1)
ZEND_END_ARG_INFO()

#define arginfo_class_Generator_key arginfo_class_Generator_current

#define arginfo_class_Generator_next arginfo_class_Generator_rewind

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_send, 0, 1, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_send, 0, 1, IS_MIXED, 1)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_throw, 0, 1, IS_MIXED, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Generator_throw, 0, 1, IS_MIXED, 1)
ZEND_ARG_OBJ_INFO(0, exception, Throwable, 0)
ZEND_END_ARG_INFO()

Expand Down
2 changes: 1 addition & 1 deletion build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static function fromNode(Node $node) {

public function isNullable(): bool {
foreach ($this->types as $type) {
if ($type->isNull()) {
if ($type->isNull() || $type->name === "mixed") {
return true;
}
}
Expand Down
6 changes: 3 additions & 3 deletions ext/filter/filter_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_has_var, 0, 2, _IS_BOOL,
ZEND_ARG_TYPE_INFO(0, variable_name, IS_STRING, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_input, 0, 2, IS_MIXED, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_input, 0, 2, IS_MIXED, 1)
ZEND_ARG_TYPE_INFO(0, type, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, variable_name, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filter, IS_LONG, 0, "FILTER_DEFAULT")
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, options, "null")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_var, 0, 1, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, variable, IS_MIXED, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_filter_var, 0, 1, IS_MIXED, 1)
ZEND_ARG_TYPE_INFO(0, variable, IS_MIXED, 1)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, filter, IS_LONG, 0, "FILTER_DEFAULT")
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, options, "null")
ZEND_END_ARG_INFO()
Expand Down
24 changes: 15 additions & 9 deletions ext/gmp/gmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,18 @@ static zend_object *gmp_clone_obj(zend_object *obj) /* {{{ */
}
/* }}} */

static void shift_operator_helper(gmp_binary_ui_op_t op, zval *return_value, zval *op1, zval *op2) {
static void shift_operator_helper(gmp_binary_ui_op_t op, zval *return_value, zval *op1, zval *op2, zend_uchar opcode) {
zend_long shift = zval_get_long(op2);

if (shift < 0) {
php_error_docref(NULL, E_WARNING, "Shift cannot be negative");
RETVAL_FALSE;
if (strcmp(get_active_function_name(), "main")) {
zend_argument_value_error(2, "must be greater than or equal to 0");
} else {
zend_throw_error(zend_ce_value_error, "%s must be greater than or equal to 0",
opcode == ZEND_POW ? "Exponent" : "Shift"
);
}
return;
} else {
mpz_ptr gmpnum_op, gmpnum_result;
gmp_temp_t temp;
Expand Down Expand Up @@ -372,17 +378,17 @@ static int gmp_do_operation_ex(zend_uchar opcode, zval *result, zval *op1, zval
case ZEND_MUL:
DO_BINARY_UI_OP(mpz_mul);
case ZEND_POW:
shift_operator_helper(mpz_pow_ui, result, op1, op2);
shift_operator_helper(mpz_pow_ui, result, op1, op2, opcode);
return SUCCESS;
case ZEND_DIV:
DO_BINARY_UI_OP_EX(mpz_tdiv_q, gmp_mpz_tdiv_q_ui, 1);
case ZEND_MOD:
DO_BINARY_UI_OP_EX(mpz_mod, gmp_mpz_mod_ui, 1);
case ZEND_SL:
shift_operator_helper(mpz_mul_2exp, result, op1, op2);
shift_operator_helper(mpz_mul_2exp, result, op1, op2, opcode);
return SUCCESS;
case ZEND_SR:
shift_operator_helper(mpz_fdiv_q_2exp, result, op1, op2);
shift_operator_helper(mpz_fdiv_q_2exp, result, op1, op2, opcode);
return SUCCESS;
case ZEND_BW_OR:
DO_BINARY_OP(mpz_ior);
Expand Down Expand Up @@ -520,7 +526,7 @@ static ZEND_GINIT_FUNCTION(gmp)
ZEND_MINIT_FUNCTION(gmp)
{
zend_class_entry tmp_ce;
INIT_CLASS_ENTRY(tmp_ce, "GMP", NULL);
INIT_CLASS_ENTRY(tmp_ce, "GMP", class_GMP_methods);
gmp_ce = zend_register_internal_class(&tmp_ce);
gmp_ce->create_object = gmp_create_object;
gmp_ce->serialize = gmp_serialize;
Expand Down Expand Up @@ -1261,8 +1267,8 @@ ZEND_FUNCTION(gmp_pow)
}

if (exp < 0) {
php_error_docref(NULL, E_WARNING, "Negative exponent not supported");
RETURN_FALSE;
zend_argument_value_error(2, "must be greater than or equal to 0");
RETURN_THROWS();
}

if (Z_TYPE_P(base_arg) == IS_LONG && Z_LVAL_P(base_arg) >= 0) {
Expand Down
4 changes: 4 additions & 0 deletions ext/gmp/gmp.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

/** @generate-function-entries */

class GMP
{
}

/** @param int|bool|string $number */
function gmp_init($number, int $base = 0): GMP|false {}

Expand Down
5 changes: 5 additions & 0 deletions ext/gmp/gmp_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,8 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(gmp_binomial, arginfo_gmp_binomial)
ZEND_FE_END
};


static const zend_function_entry class_GMP_methods[] = {
ZEND_FE_END
};
20 changes: 12 additions & 8 deletions ext/gmp/tests/gmp_pow.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ var_dump(gmp_strval(gmp_pow(-2,10)));
var_dump(gmp_strval(gmp_pow(-2,11)));
var_dump(gmp_strval(gmp_pow("2",10)));
var_dump(gmp_strval(gmp_pow("2",0)));
var_dump(gmp_strval(gmp_pow("2",-1)));
try {
gmp_pow("2", -1);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
var_dump(gmp_strval(gmp_pow("-2",10)));
var_dump(gmp_strval(gmp_pow(20,10)));
var_dump(gmp_strval(gmp_pow(50,10)));
var_dump(gmp_strval(gmp_pow(50,-5)));
try {
gmp_pow(50,-5);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

$n = gmp_init("20");
var_dump(gmp_strval(gmp_pow($n,10)));
Expand All @@ -36,15 +44,11 @@ string(4) "1024"
string(5) "-2048"
string(4) "1024"
string(1) "1"

Warning: gmp_pow(): Negative exponent not supported in %s on line %d
string(1) "0"
gmp_pow(): Argument #2 ($exp) must be greater than or equal to 0
string(4) "1024"
string(14) "10240000000000"
string(17) "97656250000000000"

Warning: gmp_pow(): Negative exponent not supported in %s on line %d
string(1) "0"
gmp_pow(): Argument #2 ($exp) must be greater than or equal to 0
string(14) "10240000000000"
string(14) "10240000000000"
gmp_pow(): Argument #2 ($exp) must be of type int, array given
Expand Down
35 changes: 35 additions & 0 deletions ext/gmp/tests/gmp_pow2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
Test pow() with gmp object
--SKIPIF--
<?php if (!extension_loaded("gmp")) print "skip"; ?>
--FILE--
<?php

$n = gmp_init(2);
var_dump(pow($n, 10));
var_dump($n ** 10);

try {
pow($n, -10);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

try {
$n ** -10;
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECTF--
object(GMP)#%d (1) {
["num"]=>
string(4) "1024"
}
object(GMP)#%d (1) {
["num"]=>
string(4) "1024"
}
pow(): Argument #2 ($exp) must be greater than or equal to 0
Exponent must be greater than or equal to 0
21 changes: 13 additions & 8 deletions ext/gmp/tests/overloading.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,17 @@ var_dump(42 << $b);
var_dump($a >> 2);
var_dump(-$a >> 2);

var_dump($a << -1);
var_dump($a >> -1);
try {
$a << -1;
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

try {
$a >> -1;
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

var_dump(~$a);
var_dump(-$a);
Expand Down Expand Up @@ -237,12 +246,8 @@ object(GMP)#%d (1) {
["num"]=>
string(3) "-11"
}

Warning: main(): Shift cannot be negative in %s on line %d
bool(false)

Warning: main(): Shift cannot be negative in %s on line %d
bool(false)
Shift must be greater than or equal to 0
Shift must be greater than or equal to 0
object(GMP)#%d (1) {
["num"]=>
string(3) "-43"
Expand Down
4 changes: 2 additions & 2 deletions ext/json/json_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* This is a generated file, edit the .stub.php file instead. */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_json_encode, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 1)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "0")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, depth, IS_LONG, 0, "512")
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_json_decode, 0, 1, IS_MIXED, 0)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_json_decode, 0, 1, IS_MIXED, 1)
ZEND_ARG_TYPE_INFO(0, json, IS_STRING, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, assoc, _IS_BOOL, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, depth, IS_LONG, 0, "512")
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/mysqli.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public function attr_set(int $attr, int $mode_in) {}
* @return bool
* @alias mysqli_stmt_bind_param
*/
public function bind_param(string $types, &...$vars) {}
public function bind_param(string $types, mixed &...$vars) {}

/**
* @return bool
Expand Down
4 changes: 2 additions & 2 deletions ext/mysqli/mysqli_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_stmt_bind_param, 0, 2, _IS_BOOL, 0)
ZEND_ARG_OBJ_INFO(0, mysql_stmt, mysqli_stmt, 0)
ZEND_ARG_TYPE_INFO(0, types, IS_STRING, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(1, vars, IS_MIXED, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(1, vars, IS_MIXED, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_mysqli_stmt_bind_result, 0, 1, _IS_BOOL, 0)
Expand Down Expand Up @@ -633,7 +633,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_stmt_bind_param, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, types, IS_STRING, 0)
ZEND_ARG_VARIADIC_INFO(1, vars)
ZEND_ARG_VARIADIC_TYPE_INFO(1, vars, IS_MIXED, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_mysqli_stmt_bind_result, 0, 0, 0)
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/zend_func_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static const func_info_t func_infos[] = {
F1("password_get_info", MAY_BE_NULL | MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_STRING | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
F1("convert_uuencode", MAY_BE_FALSE | MAY_BE_STRING),
F1("convert_uudecode", MAY_BE_FALSE | MAY_BE_STRING),
F1("pow", MAY_BE_NULL | MAY_BE_LONG | MAY_BE_DOUBLE | MAY_BE_OBJECT),
F1("pow", MAY_BE_LONG | MAY_BE_DOUBLE | MAY_BE_OBJECT),
F1("decbin", MAY_BE_STRING),
F1("decoct", MAY_BE_STRING),
F1("dechex", MAY_BE_STRING),
Expand Down
4 changes: 2 additions & 2 deletions ext/reflection/php_reflection_arginfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ZEND_END_ARG_INFO()
#define arginfo_class_ReflectionFunction_isDisabled arginfo_class_ReflectionFunctionAbstract___clone

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionFunction_invoke, 0, 0, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionFunction_invokeArgs, 0, 0, 1)
Expand Down Expand Up @@ -125,7 +125,7 @@ ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionMethod_invoke, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, object, IS_OBJECT, 1, "null")
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 0)
ZEND_ARG_VARIADIC_TYPE_INFO(0, args, IS_MIXED, 1)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ReflectionMethod_invokeArgs, 0, 0, 2)
Expand Down
Loading