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
25 changes: 25 additions & 0 deletions Zend/tests/builtin_functions/define_arg_3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
define() with 3rd argument
--FILE--
<?php

define('my_Constant', 5, true);

try {
var_dump(MY_CONSTANT);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}

define('MY_CONSTANT', 5, false);
var_dump(MY_CONSTANT);

?>
--EXPECT--
Deprecated: define(): Argument #3 ($case_insensitive) is ignored and treated as false since declaration of case-insensitive constants is no longer supported, passing the argument explicitly is unnecessary in /home/girgias/Dev/php-src/Zend/tests/builtin_functions/define_arg_3.php on line 3

Warning: define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported, this will be an error in PHP 9.0 in /home/girgias/Dev/php-src/Zend/tests/builtin_functions/define_arg_3.php on line 3
Error: Undefined constant "MY_CONSTANT"

Deprecated: define(): Argument #3 ($case_insensitive) is ignored and treated as false since declaration of case-insensitive constants is no longer supported, passing the argument explicitly is unnecessary in /home/girgias/Dev/php-src/Zend/tests/builtin_functions/define_arg_3.php on line 11
int(5)
1 change: 1 addition & 0 deletions Zend/tests/exceptions/gh16188.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ printf("__toString:\n%s\n\n", $re);
?>
==DONE==
--EXPECTF--
Deprecated: array_walk(): Passing an object for argument #1 $array to array_walk() is deprecated, call get_object_vars() first instead in %s on line %d
getTraceAsString:
#0 {main}

Expand Down
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 */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does wrapping the function into if(random_int(1, 1)) work? Otherwise you could require __DIR__ . '/readonly_as_fn_name_is_deprecated.phpt'; to reuse the other test.

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
3 changes: 2 additions & 1 deletion Zend/tests/grammar/readonly_function.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ $b->readonly();
echo $b->readonly, "\n";

?>
--EXPECT--
--EXPECTF--
Deprecated: Calling a function “readonly” is deprecated in %s on line %d
Hi!
Const hi!
Static hi!
Expand Down
1 change: 1 addition & 0 deletions Zend/tests/lazy_objects/array_walk.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var_dump($obj);

?>
--EXPECTF--
Deprecated: array_walk(): Passing an object for argument #1 $array to array_walk() is deprecated, call get_object_vars() first instead in %s on line %d
TypeError: Cannot assign string to reference held by property C::$a of type int
lazy proxy object(C)#%d (1) {
["instance"]=>
Expand Down
3 changes: 2 additions & 1 deletion Zend/tests/property_hooks/gh18268.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ array_walk($b, function (&$item) {
});

?>
--EXPECT--
--EXPECTF--
Deprecated: array_walk(): Passing an object for argument #1 $array to array_walk() is deprecated, call get_object_vars() first instead in %s on line %d
int(42)
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
14 changes: 13 additions & 1 deletion Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,25 @@ ZEND_FUNCTION(define)
Z_PARAM_BOOL(non_cs)
ZEND_PARSE_PARAMETERS_END();

if (ZEND_NUM_ARGS() == 3) {
zend_error(E_DEPRECATED,
"define(): Argument #3 ($case_insensitive) is ignored and treated as false since declaration of case-insensitive constants is no longer supported, passing the argument explicitly is unnecessary"
);
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}
}

if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) {
zend_argument_value_error(1, "cannot be a class constant");
RETURN_THROWS();
}

if (non_cs) {
zend_error(E_WARNING, "define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported");
zend_error(E_WARNING, "define(): Argument #3 ($case_insensitive) is ignored since declaration of case-insensitive constants is no longer supported, this will be an error in PHP 9.0");
if (UNEXPECTED(EG(exception))) {
RETURN_THROWS();
}
}

if (Z_TYPE_P(val) == IS_ARRAY && Z_REFCOUNTED_P(val)) {
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,
"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,
"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(): 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(): 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
3 changes: 2 additions & 1 deletion ext/ffi/tests/gh9697.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ $x = FFI::cdef()->new('int');
array_walk($x, function($x) { echo "test\n"; });
?>
DONE
--EXPECT--
--EXPECTF--
Deprecated: array_walk(): Passing an object for argument #1 $array to array_walk() is deprecated, call get_object_vars() first instead in %s on line %d
DONE
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)
Loading
Loading