Skip to content

Commit 3bf21a0

Browse files
authored
1 parent 43a9108 commit 3bf21a0

8 files changed

+80
-8
lines changed

Zend/tests/type_casts/cast_to_double.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
casting different variables to double
2+
casting different variables to float
33
--INI--
44
precision=14
55
--FILE--
@@ -32,7 +32,7 @@ $vars = array(
3232
);
3333

3434
foreach ($vars as $var) {
35-
$tmp = (double)$var;
35+
$tmp = (float)$var;
3636
var_dump($tmp);
3737
}
3838

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Non canonical (binary) cast
3+
--FILE--
4+
<?php
5+
6+
var_dump((binary) 42);
7+
8+
?>
9+
--EXPECTF--
10+
Deprecated: Non-canonical cast (binary) is deprecated, use the (string) cast instead in %s on line %d
11+
int(42)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Non canonical (boolean) cast
3+
--FILE--
4+
<?php
5+
6+
var_dump((boolean) 42);
7+
8+
?>
9+
--EXPECTF--
10+
Deprecated: Non-canonical cast (boolean) is deprecated, use the (bool) cast instead in %s on line %d
11+
int(42)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Non canonical (double) cast
3+
--FILE--
4+
<?php
5+
6+
var_dump((double) 42);
7+
8+
?>
9+
--EXPECTF--
10+
Deprecated: Non-canonical cast (double) is deprecated, use the (float) cast instead in %s on line %d
11+
int(42)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Non canonical (integer) cast
3+
--FILE--
4+
<?php
5+
6+
var_dump((integer) "42");
7+
8+
?>
9+
--EXPECTF--
10+
Deprecated: Non-canonical cast (integer) is deprecated, use the (int) cast instead in %s on line %d
11+
int(42)

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2310,7 +2310,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
23102310
case IS_NULL: PREFIX_OP("(unset)", 240, 241);
23112311
case _IS_BOOL: PREFIX_OP("(bool)", 240, 241);
23122312
case IS_LONG: PREFIX_OP("(int)", 240, 241);
2313-
case IS_DOUBLE: PREFIX_OP("(double)", 240, 241);
2313+
case IS_DOUBLE: PREFIX_OP("(float)", 240, 241);
23142314
case IS_STRING: PREFIX_OP("(string)", 240, 241);
23152315
case IS_ARRAY: PREFIX_OP("(array)", 240, 241);
23162316
case IS_OBJECT: PREFIX_OP("(object)", 240, 241);

Zend/zend_language_parser.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
212212
%token T_INC "'++'"
213213
%token T_DEC "'--'"
214214
%token T_INT_CAST "'(int)'"
215-
%token T_DOUBLE_CAST "'(double)'"
215+
%token T_DOUBLE_CAST "'(float)'"
216216
%token T_STRING_CAST "'(string)'"
217217
%token T_ARRAY_CAST "'(array)'"
218218
%token T_OBJECT_CAST "'(object)'"

Zend/zend_language_scanner.l

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,14 +1629,28 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
16291629
RETURN_TOKEN_WITH_IDENT(T_VAR);
16301630
}
16311631

1632-
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("int"|"integer"){TABS_AND_SPACES}")" {
1632+
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("int"){TABS_AND_SPACES}")" {
16331633
RETURN_TOKEN(T_INT_CAST);
16341634
}
16351635

1636-
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("double"|"float"){TABS_AND_SPACES}")" {
1636+
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("integer"){TABS_AND_SPACES}")" {
1637+
if (PARSER_MODE()) {
1638+
zend_error(E_DEPRECATED, "Non-canonical cast (integer) is deprecated, use the (int) cast instead");
1639+
}
1640+
RETURN_TOKEN(T_INT_CAST);
1641+
}
1642+
1643+
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("float"){TABS_AND_SPACES}")" {
16371644
RETURN_TOKEN(T_DOUBLE_CAST);
16381645
}
16391646

1647+
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("double"){TABS_AND_SPACES}")" {
1648+
if (PARSER_MODE()) {
1649+
zend_error(E_DEPRECATED, "Non-canonical cast (double) is deprecated, use the (float) cast instead");
1650+
}
1651+
RETURN_TOKEN(T_INT_CAST);
1652+
}
1653+
16401654
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}"real"{TABS_AND_SPACES}")" {
16411655
if (PARSER_MODE()) {
16421656
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_
16451659
RETURN_TOKEN(T_DOUBLE_CAST);
16461660
}
16471661

1648-
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("string"|"binary"){TABS_AND_SPACES}")" {
1662+
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("string"){TABS_AND_SPACES}")" {
16491663
RETURN_TOKEN(T_STRING_CAST);
16501664
}
16511665

1666+
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("binary"){TABS_AND_SPACES}")" {
1667+
if (PARSER_MODE()) {
1668+
zend_error(E_DEPRECATED, "Non-canonical cast (binary) is deprecated, use the (string) cast instead");
1669+
}
1670+
RETURN_TOKEN(T_INT_CAST);
1671+
}
1672+
16521673
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}"array"{TABS_AND_SPACES}")" {
16531674
RETURN_TOKEN(T_ARRAY_CAST);
16541675
}
@@ -1657,10 +1678,17 @@ OPTIONAL_WHITESPACE_OR_COMMENTS ({WHITESPACE}|{MULTI_LINE_COMMENT}|{SINGLE_LINE_
16571678
RETURN_TOKEN(T_OBJECT_CAST);
16581679
}
16591680

1660-
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("bool"|"boolean"){TABS_AND_SPACES}")" {
1681+
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("bool"){TABS_AND_SPACES}")" {
16611682
RETURN_TOKEN(T_BOOL_CAST);
16621683
}
16631684

1685+
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("boolean"){TABS_AND_SPACES}")" {
1686+
if (PARSER_MODE()) {
1687+
zend_error(E_DEPRECATED, "Non-canonical cast (boolean) is deprecated, use the (bool) cast instead");
1688+
}
1689+
RETURN_TOKEN(T_INT_CAST);
1690+
}
1691+
16641692
<ST_IN_SCRIPTING>"("{TABS_AND_SPACES}("unset"){TABS_AND_SPACES}")" {
16651693
RETURN_TOKEN(T_UNSET_CAST);
16661694
}

0 commit comments

Comments
 (0)