Skip to content
Draft
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
12 changes: 12 additions & 0 deletions Zend/tests/functions/readonly_as_fn_name_is_deprecated.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
Naming a function readonly is deprecated
--FILE--
<?php

function readonly() {}

?>
DONE
--EXPECTF--
Deprecated: Calling a function “readonly” is deprecated in %s on line %d
DONE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
Naming a function readonly is deprecated
--FILE--
<?php

namespace Foo;

function readonly() {}

?>
DONE
--EXPECTF--
Deprecated: Calling a function “readonly” is deprecated in %s on line %d
DONE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--TEST--
Naming a function readonly is deprecated with an error handler elevating it to an exception
--FILE--
<?php

set_error_handler(function ($number, $message) {
throw new Exception($message);
});

/* Throwing error handlers do no apply for compile time deprecations */
function readonly() {}

?>
DONE
--EXPECTF--
Deprecated: Calling a function “readonly” is deprecated in %s on line %d
DONE
13 changes: 13 additions & 0 deletions Zend/tests/functions/readonly_as_method_name_is_ok.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Naming a function readonly is deprecated
--FILE--
<?php

class C {
public function readonly() {}
}

?>
DONE
--EXPECT--
DONE
16 changes: 8 additions & 8 deletions Zend/tests/type_declarations/union_types/incdec_prop.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@ class Test {
$test = new Test;
$test->prop = PHP_INT_MAX;
$x = $test->prop++;
var_dump(is_double($test->prop));
var_dump(is_float($test->prop));

$test->prop = PHP_INT_MAX;
$x = ++$test->prop;
var_dump(is_double($test->prop));
var_dump(is_float($test->prop));

$test->prop = PHP_INT_MIN;
$x = $test->prop--;
var_dump(is_double($test->prop));
var_dump(is_float($test->prop));

$test->prop = PHP_INT_MIN;
$x = --$test->prop;
var_dump(is_double($test->prop));
var_dump(is_float($test->prop));

$test = new Test;
$test->prop = PHP_INT_MAX;
$r =& $test->prop;
$x = $test->prop++;
var_dump(is_double($test->prop));
var_dump(is_float($test->prop));

$test->prop = PHP_INT_MAX;
$x = ++$test->prop;
$r =& $test->prop;
var_dump(is_double($test->prop));
var_dump(is_float($test->prop));

$test->prop = PHP_INT_MIN;
$x = $test->prop--;
$r =& $test->prop;
var_dump(is_double($test->prop));
var_dump(is_float($test->prop));

$test->prop = PHP_INT_MIN;
$x = --$test->prop;
$r =& $test->prop;
var_dump(is_double($test->prop));
var_dump(is_float($test->prop));

/* Incrementing a non-int|float property past int min/max is an error,
* even if the result of the overflow (a float) would technically be allowed
Expand Down
17 changes: 7 additions & 10 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5387,14 +5387,9 @@ static zend_result zend_try_compile_special_func_ex(znode *result, zend_string *
return zend_compile_func_typecheck(result, args, IS_NULL);
} else if (zend_string_equals_literal(lcname, "is_bool")) {
return zend_compile_func_typecheck(result, args, _IS_BOOL);
} else if (zend_string_equals_literal(lcname, "is_long")
|| zend_string_equals_literal(lcname, "is_int")
|| zend_string_equals_literal(lcname, "is_integer")
) {
} else if (zend_string_equals_literal(lcname, "is_int")) {
return zend_compile_func_typecheck(result, args, IS_LONG);
} else if (zend_string_equals_literal(lcname, "is_float")
|| zend_string_equals_literal(lcname, "is_double")
) {
} else if (zend_string_equals_literal(lcname, "is_float")) {
return zend_compile_func_typecheck(result, args, IS_DOUBLE);
} else if (zend_string_equals_literal(lcname, "is_string")) {
return zend_compile_func_typecheck(result, args, IS_STRING);
Expand All @@ -5410,9 +5405,7 @@ static zend_result zend_try_compile_special_func_ex(znode *result, zend_string *
return zend_compile_func_cast(result, args, _IS_BOOL);
} else if (zend_string_equals_literal(lcname, "intval")) {
return zend_compile_func_cast(result, args, IS_LONG);
} else if (zend_string_equals_literal(lcname, "floatval")
|| zend_string_equals_literal(lcname, "doubleval")
) {
} else if (zend_string_equals_literal(lcname, "floatval")) {
return zend_compile_func_cast(result, args, IS_DOUBLE);
} else if (zend_string_equals_literal(lcname, "strval")) {
return zend_compile_func_cast(result, args, IS_STRING);
Expand Down Expand Up @@ -8929,6 +8922,10 @@ static zend_string *zend_begin_func_decl(znode *result, zend_op_array *op_array,
"__autoload() is no longer supported, use spl_autoload_register() instead");
}

if (zend_string_equals_literal_ci(unqualified_name, "readonly")) {
zend_error(E_DEPRECATED, "Calling a function “readonly” is deprecated");
}

if (zend_string_equals_literal_ci(unqualified_name, "assert")) {
zend_error(E_COMPILE_ERROR,
"Defining a custom assert() function is not allowed, "
Expand Down
26 changes: 20 additions & 6 deletions ext/bz2/bz2_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,19 @@ static php_stream_filter *php_bz2_decompress_filter_create(zval *filter_params,
&& Z_TYPE_P(filter_params) != IS_ARRAY
&& Z_TYPE_P(filter_params) != IS_OBJECT
)) {
php_error_docref(NULL, E_WARNING,
php_error_docref("filters.compression", E_WARNING,
"Filter parameters for bzip2.decompress filter must be of type array|object|bool, %s given",
zend_zval_type_name(filter_params)
);
return NULL;
}
if (Z_TYPE_P(filter_params) == IS_OBJECT) {
php_error_docref("filters.compression", E_DEPRECATED,
"Deprecated: Passing an object for filter parameters for bzip2.decompress is deprecated, call get_object_vars() first instead");
if (UNEXPECTED(EG(exception))) {
return NULL;
}
}

if (Z_TYPE_P(filter_params) == IS_TRUE || Z_TYPE_P(filter_params) == IS_FALSE) {
small_footprint = Z_TYPE_P(filter_params) == IS_TRUE;
Expand Down Expand Up @@ -448,12 +455,19 @@ static php_stream_filter *php_bz2_compress_filter_create(zval *filter_params, bo

if (filter_params) {
if (UNEXPECTED(Z_TYPE_P(filter_params) != IS_ARRAY && Z_TYPE_P(filter_params) != IS_OBJECT)) {
php_error_docref(NULL, E_WARNING,
php_error_docref("filters.compression", E_WARNING,
"Filter parameters for bzip2.compress filter must be of type array|object, %s given",
zend_zval_type_name(filter_params)
);
return NULL;
}
if (Z_TYPE_P(filter_params) == IS_OBJECT) {
php_error_docref("filters.compression", E_DEPRECATED,
"Deprecated: Passing an object for filter parameters for bzip2.compress is deprecated, call get_object_vars() first instead");
if (UNEXPECTED(EG(exception))) {
return NULL;
}
}

const HashTable *filter_params_ht = HASH_OF(filter_params);
/* TODO: convert php_stream_filter_parse_write_seek_mode() to take HashTable */
Expand All @@ -468,10 +482,10 @@ static php_stream_filter *php_bz2_compress_filter_create(zval *filter_params, bo
/* How much memory to allocate (1 - 9) x 100kb */
zend_long blocks = zval_try_get_long(blocks_zv, &failed);
if (UNEXPECTED(failed)) {
php_error_docref(NULL, E_WARNING, "Number of blocks parameter must be of type int, %s given", zend_zval_type_name(blocks_zv));
php_error_docref("filters.compression", E_WARNING, "Number of blocks parameter must be of type int, %s given", zend_zval_type_name(blocks_zv));
return NULL;
} else if (blocks < 1 || blocks > 9) {
php_error_docref(NULL, E_WARNING, "Number of blocks to allocate must be between 1 and 9, " ZEND_LONG_FMT " given", blocks);
php_error_docref("filters.compression", E_WARNING, "Number of blocks to allocate must be between 1 and 9, " ZEND_LONG_FMT " given", blocks);
return NULL;
} else {
blockSize100k = (int) blocks;
Expand All @@ -485,10 +499,10 @@ static php_stream_filter *php_bz2_compress_filter_create(zval *filter_params, bo
/* Work Factor (0 - 250) */
zend_long work = zval_try_get_long(work_zv, &failed);
if (UNEXPECTED(failed)) {
php_error_docref(NULL, E_WARNING, "Work factor parameter must be of type int, %s given", zend_zval_type_name(work_zv));
php_error_docref("filters.compression", E_WARNING, "Work factor parameter must be of type int, %s given", zend_zval_type_name(work_zv));
return NULL;
} else if (work < 0 || work > 250) {
php_error_docref(NULL, E_WARNING, "Work factor must be between 0 and 250, " ZEND_LONG_FMT " given", work);
php_error_docref("filters.compression", E_WARNING, "Work factor must be between 0 and 250, " ZEND_LONG_FMT " given", work);
return NULL;
} else {
workFactor = (int) work;
Expand Down
5 changes: 4 additions & 1 deletion ext/bz2/tests/filter_broken_object_options.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ stream_filter_append($fp, 'bzip2.decompress', STREAM_FILTER_WRITE, new ParamsDec
fwrite($fp, "Hello world, hopefully not broken\n");

?>
--EXPECT--
--EXPECTF--
Deprecated: stream_filter_append(): Deprecated: Passing an object for filter parameters for bzip2.compress is deprecated, call get_object_vars() first instead in %s on line %d

Deprecated: stream_filter_append(): Deprecated: Passing an object for filter parameters for bzip2.decompress is deprecated, call get_object_vars() first instead in %s on line %d
Hello world, hopefully not broken
2 changes: 1 addition & 1 deletion ext/date/tests/strtotime-mysql-64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $d[] = '20800410101010'; // overflow..
foreach($d as $date) {
$time = strtotime($date);

if (is_integer($time)) {
if (is_int($time)) {
var_dump(date('r', $time));
} else {
var_dump($time);
Expand Down
2 changes: 1 addition & 1 deletion ext/date/tests/strtotime-mysql.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $d[] = '20800410101010'; // overflow..
foreach($d as $date) {
$time = strtotime($date);

if (is_integer($time)) {
if (is_int($time)) {
var_dump(date('r', $time));
} else {
var_dump($time);
Expand Down
2 changes: 1 addition & 1 deletion ext/date/tests/strtotime3-64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $strs = array(

foreach ($strs as $str) {
$t = strtotime($str, $time);
if (is_integer($t)) {
if (is_int($t)) {
var_dump(date(DATE_RFC2822, $t));
} else {
var_dump($t);
Expand Down
2 changes: 1 addition & 1 deletion ext/date/tests/strtotime3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $strs = array(

foreach ($strs as $str) {
$t = strtotime($str, $time);
if (is_integer($t)) {
if (is_int($t)) {
var_dump(date(DATE_RFC2822, $t));
} else {
var_dump($t);
Expand Down
10 changes: 5 additions & 5 deletions ext/filter/tests/046.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ default:
function test_validation($val, $msg) {
$f = filter_var($val, FILTER_VALIDATE_INT);
echo "$msg filtered: "; var_dump($f); // filtered value (or false)
echo "$msg is_long: "; var_dump(is_long($f)); // test validation
echo "$msg is_int: "; var_dump(is_int($f)); // test validation
echo "$msg equal: "; var_dump($val == $f); // test equality of result
}

Expand All @@ -36,14 +36,14 @@ test_validation($underflow, "underflow");
?>
--EXPECTF--
max filtered: int(%d)
max is_long: bool(true)
max is_int: bool(true)
max equal: bool(true)
overflow filtered: bool(false)
overflow is_long: bool(false)
overflow is_int: bool(false)
overflow equal: bool(false)
min filtered: int(-%d)
min is_long: bool(true)
min is_int: bool(true)
min equal: bool(true)
underflow filtered: bool(false)
underflow is_long: bool(false)
underflow is_int: bool(false)
underflow equal: bool(false)
6 changes: 3 additions & 3 deletions ext/filter/tests/047.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ function octal_inc($s) {


$s = sprintf("%o", PHP_INT_MAX);
var_dump(is_long(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));
var_dump(is_int(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));

$s = octal_inc($s);
var_dump(is_long(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));
var_dump(is_int(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));

$s = sprintf("%o", ~0);
var_dump(is_long(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));
var_dump(is_int(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))));

$s = octal_inc($s);
var_dump(filter_var('0'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL)));
Expand Down
6 changes: 3 additions & 3 deletions ext/filter/tests/048.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ function hex_inc($s) {


$s = sprintf("%x", PHP_INT_MAX);
var_dump(is_long(filter_var('0x'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_HEX))));
var_dump(is_int(filter_var('0x'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_HEX))));

$s = hex_inc($s);
var_dump(is_long(filter_var('0x'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_HEX))));
var_dump(is_int(filter_var('0x'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_HEX))));

$s = sprintf("%x", ~0);
var_dump(is_long(filter_var('0x'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_HEX))));
var_dump(is_int(filter_var('0x'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_HEX))));

$s = hex_inc($s);
var_dump(filter_var('0x'.$s, FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_HEX)));
Expand Down
23 changes: 20 additions & 3 deletions ext/mbstring/mbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -3820,7 +3820,7 @@ static bool mb_recursive_find_strings(zval *var, const unsigned char **val_list,
return false;
}

static bool mb_recursive_convert_variable(zval *var, const mbfl_encoding* from_encoding, const mbfl_encoding* to_encoding)
static bool mb_recursive_convert_variable(uint32_t arg_num, zval *var, const mbfl_encoding* from_encoding, const mbfl_encoding* to_encoding)
{
zval *entry, *orig_var;

Expand All @@ -3836,6 +3836,15 @@ static bool mb_recursive_convert_variable(zval *var, const mbfl_encoding* from_e
zval_ptr_dtor(orig_var);
ZVAL_STR(orig_var, ret);
} else if (Z_TYPE_P(var) == IS_ARRAY || Z_TYPE_P(var) == IS_OBJECT) {
if (Z_TYPE_P(var) == IS_OBJECT) {
php_error_docref(NULL, E_WARNING,
"Passing an object for argument #%" PRIu32 " $vars to mb_convert_variables() is deprecated, call get_object_vars() first instead",
arg_num
);
if (UNEXPECTED(EG(exception))) {
return true;
}
}
HashTable *ht = HASH_OF(var);
HashTable *orig_ht = ht;

Expand Down Expand Up @@ -3872,7 +3881,7 @@ static bool mb_recursive_convert_variable(zval *var, const mbfl_encoding* from_e
}
}

if (mb_recursive_convert_variable(entry, from_encoding, to_encoding)) {
if (mb_recursive_convert_variable(arg_num, entry, from_encoding, to_encoding)) {
if (ht && ht != orig_ht) {
GC_TRY_UNPROTECT_RECURSION(ht);
}
Expand All @@ -3890,6 +3899,14 @@ static bool mb_recursive_convert_variable(zval *var, const mbfl_encoding* from_e
if (orig_ht) {
GC_TRY_UNPROTECT_RECURSION(orig_ht);
}
} else if (Z_TYPE_P(var) != IS_UNDEF) { /* Ignore unset properties */
php_error_docref(NULL, E_WARNING,
"Argument #%" PRIu32 " must be of type string|array|object or only contain entries of type string|array|object, %s given",
arg_num, zend_zval_type_name(var)
);
if (UNEXPECTED(EG(exception))) {
return true;
}
}

return false;
Expand Down Expand Up @@ -3985,7 +4002,7 @@ PHP_FUNCTION(mb_convert_variables)
for (size_t n = 0; n < argc; n++) {
zval *zv = &args[n];
ZVAL_DEREF(zv);
if (mb_recursive_convert_variable(zv, from_encoding, to_encoding)) {
if (mb_recursive_convert_variable(n + 3, zv, from_encoding, to_encoding)) {
if (!EG(exception)) {
php_error_docref(NULL, E_WARNING, "Cannot handle recursive references");
}
Expand Down
3 changes: 2 additions & 1 deletion ext/mbstring/tests/gh16261.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ mb_convert_variables("EUC-JP", "Shift_JIS", $test->x);

var_dump($test, $test2);
?>
--EXPECT--
--EXPECTF--
Warning: mb_convert_variables(): Passing an object for argument #3 $vars to mb_convert_variables() is deprecated, call get_object_vars() first instead in %s on line %d
object(Test)#1 (2) {
["x"]=>
string(5) "hello"
Expand Down
Loading
Loading