mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Remove depreacted curly brace offset syntax
Closes GH-5221
This commit is contained in:
parent
a307e48d67
commit
c803499e23
8 changed files with 22 additions and 80 deletions
|
@ -8,14 +8,7 @@ try {
|
||||||
} catch (Error $e) {
|
} catch (Error $e) {
|
||||||
echo $e->getMessage(), "\n";
|
echo $e->getMessage(), "\n";
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
$a{function() { }} = 1;
|
|
||||||
} catch (Error $e) {
|
|
||||||
echo $e->getMessage(), "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECT--
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s on line %d
|
|
||||||
Illegal offset type
|
|
||||||
Illegal offset type
|
Illegal offset type
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
--TEST--
|
||||||
|
Alternative offset syntax should emit E_COMPILE_ERROR in const expression
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
const FOO_COMPILE_ERROR = "BAR"{0};
|
||||||
|
var_dump(FOO_COMPILE_ERROR);
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Fatal error: Array and string offset access syntax with curly braces is no longer supported in %s on line 2
|
|
@ -0,0 +1,9 @@
|
||||||
|
--TEST--
|
||||||
|
Alternative offset syntax should emit E_COMPILE_ERROR outside const expression
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
$foo = 'BAR';
|
||||||
|
var_dump($foo{0});
|
||||||
|
?>
|
||||||
|
--EXPECTF--
|
||||||
|
Fatal error: Array and string offset access syntax with curly braces is no longer supported in %s on line 3
|
|
@ -5,12 +5,6 @@ Constant expressions with null coalescing operator ??
|
||||||
|
|
||||||
const A = [1 => [[]]];
|
const A = [1 => [[]]];
|
||||||
|
|
||||||
// should produce deprecation notices
|
|
||||||
const D_1 = null ?? A[1]{'undefined'}['index'] ?? 1;
|
|
||||||
const D_2 = null ?? A['undefined']{'index'} ?? 2;
|
|
||||||
const D_3 = null ?? A[1]{0}{2} ?? 3; // 2 deprecation notices
|
|
||||||
const D_4 = A[1]{0} ?? 4;
|
|
||||||
|
|
||||||
const T_1 = null ?? A[1]['undefined']['index'] ?? 1;
|
const T_1 = null ?? A[1]['undefined']['index'] ?? 1;
|
||||||
const T_2 = null ?? A['undefined']['index'] ?? 2;
|
const T_2 = null ?? A['undefined']['index'] ?? 2;
|
||||||
const T_3 = null ?? A[1][0][2] ?? 3;
|
const T_3 = null ?? A[1][0][2] ?? 3;
|
||||||
|
@ -18,11 +12,6 @@ const T_4 = A[1][0][2] ?? 4;
|
||||||
const T_5 = null ?? __LINE__;
|
const T_5 = null ?? __LINE__;
|
||||||
const T_6 = __LINE__ ?? "bar";
|
const T_6 = __LINE__ ?? "bar";
|
||||||
|
|
||||||
var_dump(D_1);
|
|
||||||
var_dump(D_2);
|
|
||||||
var_dump(D_3);
|
|
||||||
var_dump(D_4);
|
|
||||||
|
|
||||||
var_dump(T_1);
|
var_dump(T_1);
|
||||||
var_dump(T_2);
|
var_dump(T_2);
|
||||||
var_dump(T_3);
|
var_dump(T_3);
|
||||||
|
@ -42,21 +31,6 @@ var_dump((new class { public $var = A[1][0][2] ?? 4; })->var);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
int(1)
|
|
||||||
int(2)
|
|
||||||
int(3)
|
|
||||||
array(0) {
|
|
||||||
}
|
|
||||||
int(1)
|
int(1)
|
||||||
int(2)
|
int(2)
|
||||||
int(3)
|
int(3)
|
||||||
|
|
|
@ -15,7 +15,6 @@ $weird = [0 => (object) ['foo' => 'Test']];
|
||||||
|
|
||||||
var_dump(new $className);
|
var_dump(new $className);
|
||||||
var_dump(new $array['className']);
|
var_dump(new $array['className']);
|
||||||
var_dump(new $array{'className'});
|
|
||||||
var_dump(new $obj->className);
|
var_dump(new $obj->className);
|
||||||
var_dump(new Test::$className);
|
var_dump(new Test::$className);
|
||||||
var_dump(new $test::$className);
|
var_dump(new $test::$className);
|
||||||
|
@ -23,9 +22,6 @@ var_dump(new $weird[0]->foo::$className);
|
||||||
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s on line %d
|
|
||||||
object(stdClass)#%d (0) {
|
|
||||||
}
|
|
||||||
object(stdClass)#%d (0) {
|
object(stdClass)#%d (0) {
|
||||||
}
|
}
|
||||||
object(stdClass)#%d (0) {
|
object(stdClass)#%d (0) {
|
||||||
|
|
|
@ -2626,9 +2626,8 @@ static inline void zend_emit_assign_znode(zend_ast *var_ast, znode *value_node)
|
||||||
static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
|
static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
|
||||||
{
|
{
|
||||||
if (ast->attr == ZEND_DIM_ALTERNATIVE_SYNTAX) {
|
if (ast->attr == ZEND_DIM_ALTERNATIVE_SYNTAX) {
|
||||||
zend_error(E_DEPRECATED, "Array and string offset access syntax with curly braces is deprecated");
|
zend_error(E_COMPILE_ERROR, "Array and string offset access syntax with curly braces is no longer supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
zend_ast *var_ast = ast->child[0];
|
zend_ast *var_ast = ast->child[0];
|
||||||
zend_ast *dim_ast = ast->child[1];
|
zend_ast *dim_ast = ast->child[1];
|
||||||
zend_op *opline;
|
zend_op *opline;
|
||||||
|
@ -9183,7 +9182,7 @@ void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
|
||||||
|
|
||||||
if (ast->attr & ZEND_DIM_ALTERNATIVE_SYNTAX) {
|
if (ast->attr & ZEND_DIM_ALTERNATIVE_SYNTAX) {
|
||||||
ast->attr &= ~ZEND_DIM_ALTERNATIVE_SYNTAX; /* remove flag to avoid duplicate warning */
|
ast->attr &= ~ZEND_DIM_ALTERNATIVE_SYNTAX; /* remove flag to avoid duplicate warning */
|
||||||
zend_error(E_DEPRECATED, "Array and string offset access syntax with curly braces is deprecated");
|
zend_error(E_COMPILE_ERROR, "Array and string offset access syntax with curly braces is no longer supported");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
|
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
|
||||||
|
|
|
@ -11,7 +11,7 @@ error_reporting=2039
|
||||||
function hexdump($str) {
|
function hexdump($str) {
|
||||||
$len = strlen($str);
|
$len = strlen($str);
|
||||||
for ($i = 0; $i < $len; ++$i) {
|
for ($i = 0; $i < $len; ++$i) {
|
||||||
printf("%02x", ord($str{$i}));
|
printf("%02x", ord($str[$i]));
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,34 +12,8 @@ var_dump(isset($string[0][0]));
|
||||||
var_dump($string["foo"]);
|
var_dump($string["foo"]);
|
||||||
var_dump(isset($string["foo"]["bar"]));
|
var_dump(isset($string["foo"]["bar"]));
|
||||||
|
|
||||||
const FOO_DEPRECATED = "BAR"{0};
|
|
||||||
var_dump(FOO_DEPRECATED);
|
|
||||||
var_dump([$string{0}]); // 1 notice
|
|
||||||
var_dump($string{1});
|
|
||||||
var_dump(isset($string{0}));
|
|
||||||
var_dump(isset($string{0}{0})); // 2 notices
|
|
||||||
var_dump($string{"foo"});
|
|
||||||
var_dump(isset($string{"foo"}{"bar"})); // 2 notices
|
|
||||||
?>
|
?>
|
||||||
--EXPECTF--
|
--EXPECTF--
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
|
|
||||||
Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
|
|
||||||
string(1) "B"
|
string(1) "B"
|
||||||
string(1) "f"
|
string(1) "f"
|
||||||
string(1) "o"
|
string(1) "o"
|
||||||
|
@ -49,15 +23,3 @@ bool(true)
|
||||||
Warning: Illegal string offset 'foo' in %s line %d
|
Warning: Illegal string offset 'foo' in %s line %d
|
||||||
string(1) "f"
|
string(1) "f"
|
||||||
bool(false)
|
bool(false)
|
||||||
string(1) "B"
|
|
||||||
array(1) {
|
|
||||||
[0]=>
|
|
||||||
string(1) "f"
|
|
||||||
}
|
|
||||||
string(1) "o"
|
|
||||||
bool(true)
|
|
||||||
bool(true)
|
|
||||||
|
|
||||||
Warning: Illegal string offset 'foo' in %s line %d
|
|
||||||
string(1) "f"
|
|
||||||
bool(false)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue