mirror of
https://github.com/php/php-src.git
synced 2025-08-15 13:38:49 +02:00
Zend: Deprecate non-canonical cast names (#19372)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_non-standard_cast_names
This commit is contained in:
parent
43a91089ca
commit
3bf21a0d43
8 changed files with 80 additions and 8 deletions
|
@ -1,5 +1,5 @@
|
||||||
--TEST--
|
--TEST--
|
||||||
casting different variables to double
|
casting different variables to float
|
||||||
--INI--
|
--INI--
|
||||||
precision=14
|
precision=14
|
||||||
--FILE--
|
--FILE--
|
||||||
|
@ -32,7 +32,7 @@ $vars = array(
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ($vars as $var) {
|
foreach ($vars as $var) {
|
||||||
$tmp = (double)$var;
|
$tmp = (float)$var;
|
||||||
var_dump($tmp);
|
var_dump($tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
11
Zend/tests/type_casts/non_canonical_binary_cast.phpt
Normal file
11
Zend/tests/type_casts/non_canonical_binary_cast.phpt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
--TEST--
|
||||||
|
Non canonical (binary) cast
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
var_dump((binary) 42);
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Deprecated: Non-canonical cast (binary) is deprecated, use the (string) cast instead in %s on line %d
|
||||||
|
int(42)
|
11
Zend/tests/type_casts/non_canonical_boolean_cast.phpt
Normal file
11
Zend/tests/type_casts/non_canonical_boolean_cast.phpt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
--TEST--
|
||||||
|
Non canonical (boolean) cast
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
var_dump((boolean) 42);
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Deprecated: Non-canonical cast (boolean) is deprecated, use the (bool) cast instead in %s on line %d
|
||||||
|
int(42)
|
11
Zend/tests/type_casts/non_canonical_double_cast.phpt
Normal file
11
Zend/tests/type_casts/non_canonical_double_cast.phpt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
--TEST--
|
||||||
|
Non canonical (double) cast
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
var_dump((double) 42);
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Deprecated: Non-canonical cast (double) is deprecated, use the (float) cast instead in %s on line %d
|
||||||
|
int(42)
|
11
Zend/tests/type_casts/non_canonical_integer_cast.phpt
Normal file
11
Zend/tests/type_casts/non_canonical_integer_cast.phpt
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
--TEST--
|
||||||
|
Non canonical (integer) cast
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
var_dump((integer) "42");
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Deprecated: Non-canonical cast (integer) is deprecated, use the (int) cast instead in %s on line %d
|
||||||
|
int(42)
|
|
@ -2310,7 +2310,7 @@ simple_list:
|
||||||
case IS_NULL: PREFIX_OP("(unset)", 240, 241);
|
case IS_NULL: PREFIX_OP("(unset)", 240, 241);
|
||||||
case _IS_BOOL: PREFIX_OP("(bool)", 240, 241);
|
case _IS_BOOL: PREFIX_OP("(bool)", 240, 241);
|
||||||
case IS_LONG: PREFIX_OP("(int)", 240, 241);
|
case IS_LONG: PREFIX_OP("(int)", 240, 241);
|
||||||
case IS_DOUBLE: PREFIX_OP("(double)", 240, 241);
|
case IS_DOUBLE: PREFIX_OP("(float)", 240, 241);
|
||||||
case IS_STRING: PREFIX_OP("(string)", 240, 241);
|
case IS_STRING: PREFIX_OP("(string)", 240, 241);
|
||||||
case IS_ARRAY: PREFIX_OP("(array)", 240, 241);
|
case IS_ARRAY: PREFIX_OP("(array)", 240, 241);
|
||||||
case IS_OBJECT: PREFIX_OP("(object)", 240, 241);
|
case IS_OBJECT: PREFIX_OP("(object)", 240, 241);
|
||||||
|
|
|
@ -212,7 +212,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
|
||||||
%token T_INC "'++'"
|
%token T_INC "'++'"
|
||||||
%token T_DEC "'--'"
|
%token T_DEC "'--'"
|
||||||
%token T_INT_CAST "'(int)'"
|
%token T_INT_CAST "'(int)'"
|
||||||
%token T_DOUBLE_CAST "'(double)'"
|
%token T_DOUBLE_CAST "'(float)'"
|
||||||
%token T_STRING_CAST "'(string)'"
|
%token T_STRING_CAST "'(string)'"
|
||||||
%token T_ARRAY_CAST "'(array)'"
|
%token T_ARRAY_CAST "'(array)'"
|
||||||
%token T_OBJECT_CAST "'(object)'"
|
%token T_OBJECT_CAST "'(object)'"
|
||||||
|
|
|
@ -1629,14 +1629,28 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
|
||||||
RETURN_TOKEN_WITH_IDENT(T_VAR);
|
RETURN_TOKEN_WITH_IDENT(T_VAR);
|
||||||
}
|
}
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("int"|"integer"){TABS_AND_SPACES}")" {
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("int"){TABS_AND_SPACES}")" {
|
||||||
RETURN_TOKEN(T_INT_CAST);
|
RETURN_TOKEN(T_INT_CAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("double"|"float"){TABS_AND_SPACES}")" {
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("integer"){TABS_AND_SPACES}")" {
|
||||||
|
if (PARSER_MODE()) {
|
||||||
|
zend_error(E_DEPRECATED, "Non-canonical cast (integer) is deprecated, use the (int) cast instead");
|
||||||
|
}
|
||||||
|
RETURN_TOKEN(T_INT_CAST);
|
||||||
|
}
|
||||||
|
|
||||||
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("float"){TABS_AND_SPACES}")" {
|
||||||
RETURN_TOKEN(T_DOUBLE_CAST);
|
RETURN_TOKEN(T_DOUBLE_CAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("double"){TABS_AND_SPACES}")" {
|
||||||
|
if (PARSER_MODE()) {
|
||||||
|
zend_error(E_DEPRECATED, "Non-canonical cast (double) is deprecated, use the (float) cast instead");
|
||||||
|
}
|
||||||
|
RETURN_TOKEN(T_INT_CAST);
|
||||||
|
}
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}"real"{TABS_AND_SPACES}")" {
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}"real"{TABS_AND_SPACES}")" {
|
||||||
if (PARSER_MODE()) {
|
if (PARSER_MODE()) {
|
||||||
zend_throw_exception(zend_ce_parse_error, "The (real) cast has been removed, use (float) instead", 0);
|
zend_throw_exception(zend_ce_parse_error, "The (real) cast has been removed, use (float) instead", 0);
|
||||||
|
@ -1645,10 +1659,17 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
|
||||||
RETURN_TOKEN(T_DOUBLE_CAST);
|
RETURN_TOKEN(T_DOUBLE_CAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("string"|"binary"){TABS_AND_SPACES}")" {
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("string"){TABS_AND_SPACES}")" {
|
||||||
RETURN_TOKEN(T_STRING_CAST);
|
RETURN_TOKEN(T_STRING_CAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("binary"){TABS_AND_SPACES}")" {
|
||||||
|
if (PARSER_MODE()) {
|
||||||
|
zend_error(E_DEPRECATED, "Non-canonical cast (binary) is deprecated, use the (string) cast instead");
|
||||||
|
}
|
||||||
|
RETURN_TOKEN(T_INT_CAST);
|
||||||
|
}
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}"array"{TABS_AND_SPACES}")" {
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}"array"{TABS_AND_SPACES}")" {
|
||||||
RETURN_TOKEN(T_ARRAY_CAST);
|
RETURN_TOKEN(T_ARRAY_CAST);
|
||||||
}
|
}
|
||||||
|
@ -1657,10 +1678,17 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
|
||||||
RETURN_TOKEN(T_OBJECT_CAST);
|
RETURN_TOKEN(T_OBJECT_CAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("bool"|"boolean"){TABS_AND_SPACES}")" {
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("bool"){TABS_AND_SPACES}")" {
|
||||||
RETURN_TOKEN(T_BOOL_CAST);
|
RETURN_TOKEN(T_BOOL_CAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("boolean"){TABS_AND_SPACES}")" {
|
||||||
|
if (PARSER_MODE()) {
|
||||||
|
zend_error(E_DEPRECATED, "Non-canonical cast (boolean) is deprecated, use the (bool) cast instead");
|
||||||
|
}
|
||||||
|
RETURN_TOKEN(T_INT_CAST);
|
||||||
|
}
|
||||||
|
|
||||||
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("unset"){TABS_AND_SPACES}")" {
|
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("unset"){TABS_AND_SPACES}")" {
|
||||||
RETURN_TOKEN(T_UNSET_CAST);
|
RETURN_TOKEN(T_UNSET_CAST);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue