$a ? $b : ($c ? $d : $e)
RFC: https://wiki.php.net/rfc/ternary_associativity
+ . The array and string offset access syntax using curly braces is deprecated.
+ Use $str[$idx] instead of $str{$idx}.
+ RFC: https://wiki.php.net/rfc/deprecate_curly_braces_array_access
. Unbinding $this of a non-static method through a combination of
ReflectionMethod::getClosure() and closure rebinding is deprecated. Doing
so is equivalent to calling a non-static method statically, which has been
?>
--EXPECTF--
+
+Deprecated: Array and string offset access syntax with curly braces is deprecated in %s line %d
+
Warning: Illegal offset type in %s on line %d
Warning: Illegal offset type in %s on line %d
<?php
$str = "abc";
-var_dump($str{0} = "");
-var_dump($str{1} = "");
-var_dump($str{3} = "");
-var_dump($str{10} = "");
+var_dump($str[0] = "");
+var_dump($str[1] = "");
+var_dump($str[3] = "");
+var_dump($str[10] = "");
var_dump($str);
?>
==DONE==
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_2 = null ?? A['undefined']['index'] ?? 2;
const T_3 = null ?? A[1][0][2] ?? 3;
const T_5 = null ?? __LINE__;
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_2);
var_dump(T_3);
?>
--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(2)
int(3)
$i = 3;
$j = -4;
-$str{2} = 'C';
+$str[2] = 'C';
var_dump($str);
-$str{$i} = 'Z';
+$str[$i] = 'Z';
var_dump($str);
-$str{-5} = 'P';
+$str[-5] = 'P';
var_dump($str);
-$str{$j} = 'Q';
+$str[$j] = 'Q';
var_dump($str);
-$str{-20} = 'Y';
+$str[-20] = 'Y';
var_dump($str);
-$str{-strlen($str)} = strtoupper($str{0}); /* An exotic ucfirst() ;) */
+$str[-strlen($str)] = strtoupper($str[0]); /* An exotic ucfirst() ;) */
var_dump($str);
-$str{20} = 'N';
+$str[20] = 'N';
var_dump($str);
-$str{-2} = 'UFO';
+$str[-2] = 'UFO';
var_dump($str);
-$str{-$i} = $str{$j*2};
+$str[-$i] = $str[$j*2];
var_dump($str);
?>
--EXPECTF--
zval_ptr_dtor_nogc(&op1);
ret = FAILURE;
} else {
- zend_fetch_dimension_const(result, &op1, &op2, (ast->attr == ZEND_DIM_IS) ? BP_VAR_IS : BP_VAR_R);
+ zend_fetch_dimension_const(result, &op1, &op2, (ast->attr & ZEND_DIM_IS) ? BP_VAR_IS : BP_VAR_R);
zval_ptr_dtor_nogc(&op1);
zval_ptr_dtor_nogc(&op2);
static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
{
+ if (ast->attr == ZEND_DIM_ALTERNATIVE_SYNTAX) {
+ zend_error(E_DEPRECATED, "Array and string offset access syntax with curly braces is deprecated");
+ }
+
zend_ast *var_ast = ast->child[0];
zend_ast *dim_ast = ast->child[1];
zend_op *opline;
case ZEND_AST_COALESCE:
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
if (ast->child[0]->kind == ZEND_AST_DIM) {
- ast->child[0]->attr = ZEND_DIM_IS;
+ ast->child[0]->attr |= ZEND_DIM_IS;
}
zend_eval_const_expr(&ast->child[0]);
zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
}
+ if (ast->attr & ZEND_DIM_ALTERNATIVE_SYNTAX) {
+ 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");
+ }
+
/* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
- if (ast->attr == ZEND_DIM_IS && ast->child[0]->kind == ZEND_AST_DIM) {
- ast->child[0]->attr = ZEND_DIM_IS;
+ if (ast->attr & ZEND_DIM_IS && ast->child[0]->kind == ZEND_AST_DIM) {
+ ast->child[0]->attr |= ZEND_DIM_IS;
}
zend_eval_const_expr(&ast->child[0]);
#define ZEND_SEND_BY_REF 1u
#define ZEND_SEND_PREFER_REF 2u
-#define ZEND_DIM_IS 1
+#define ZEND_DIM_IS (1 << 0) /* isset fetch needed for null coalesce */
+#define ZEND_DIM_ALTERNATIVE_SYNTAX (1 << 1) /* deprecated curly brace usage */
#define IS_CONSTANT_UNQUALIFIED 0x010
#define IS_CONSTANT_CLASS 0x080 /* __CLASS__ in trait */
| constant '[' optional_expr ']'
{ $$ = zend_ast_create(ZEND_AST_DIM, $1, $3); }
| dereferencable '{' expr '}'
- { $$ = zend_ast_create(ZEND_AST_DIM, $1, $3); }
+ { $$ = zend_ast_create_ex(ZEND_AST_DIM, ZEND_DIM_ALTERNATIVE_SYNTAX, $1, $3); }
| dereferencable T_OBJECT_OPERATOR property_name argument_list
{ $$ = zend_ast_create(ZEND_AST_METHOD_CALL, $1, $3, $4); }
| function_call { $$ = $1; }
$data2 = bzcompress($string, 1, 10);
$data3 = $data2;
-$data3{3} = 0;
+$data3[3] = 0;
var_dump(bzdecompress());
var_dump(bzdecompress(1,1,1));
exit;
}
-var_dump($headers1['Title']{0} === '?');
-var_dump($headers1['Author']{0} === '?');
+var_dump($headers1['Title'][0] === '?');
+var_dump($headers1['Author'][0] === '?');
ini_set('exif.decode_unicode_motorola', 'UCS-2LE');
if ($MPEGaudioHeaderLengthCache[$head4] > 4) {
$WhereWeWere = mftell();
$next4 = test(4);
- if ($next4{0} == "\xFF") {
+ if ($next4[0] == "\xFF") {
if (!isset($MPEGaudioHeaderDecodeCache[$next4])) {
$MPEGaudioHeaderDecodeCache[$next4] = MPEGaudioHeaderDecode($next4);
}
var_dump(gzuncompress($data1));
var_dump(gzuncompress($data2));
-$data2{4} = 0;
+$data2[4] = 0;
var_dump(gzuncompress($data2));
echo "Done\n";
var_dump(gzinflate($data1));
var_dump(gzinflate($data2));
-$data2{4} = 0;
+$data2[4] = 0;
var_dump(gzinflate($data2));
echo "Done\n";
$settings .= " -d \"$name=$val\"";
}
} else {
- if (substr(PHP_OS, 0, 3) == "WIN" && !empty($value) && $value{0} == '"') {
+ if (substr(PHP_OS, 0, 3) == "WIN" && !empty($value) && $value[0] == '"') {
$len = strlen($value);
- if ($value{$len - 1} == '"') {
- $value{0} = "'";
- $value{$len - 1} = "'";
+ if ($value[$len - 1] == '"') {
+ $value[0] = "'";
+ $value[$len - 1] = "'";
}
} else {
$value = addslashes($value);
while ($p != $length) {
- $nlen = ord($data{$p++});
+ $nlen = ord($data[$p++]);
if ($nlen >= 128) {
$nlen = ($nlen & 0x7F << 24);
- $nlen |= (ord($data{$p++}) << 16);
- $nlen |= (ord($data{$p++}) << 8);
- $nlen |= (ord($data{$p++}));
+ $nlen |= (ord($data[$p++]) << 16);
+ $nlen |= (ord($data[$p++]) << 8);
+ $nlen |= (ord($data[$p++]));
}
- $vlen = ord($data{$p++});
+ $vlen = ord($data[$p++]);
if ($vlen >= 128) {
$vlen = ($nlen & 0x7F << 24);
- $vlen |= (ord($data{$p++}) << 16);
- $vlen |= (ord($data{$p++}) << 8);
- $vlen |= (ord($data{$p++}));
+ $vlen |= (ord($data[$p++]) << 16);
+ $vlen |= (ord($data[$p++]) << 8);
+ $vlen |= (ord($data[$p++]));
}
$array[substr($data, $p, $nlen)] = substr($data, $p+$nlen, $vlen);
$p += ($nlen + $vlen);
private function decodePacketHeader($data)
{
$ret = array();
- $ret['version'] = ord($data{0});
- $ret['type'] = ord($data{1});
- $ret['requestId'] = (ord($data{2}) << 8) + ord($data{3});
- $ret['contentLength'] = (ord($data{4}) << 8) + ord($data{5});
- $ret['paddingLength'] = ord($data{6});
- $ret['reserved'] = ord($data{7});
+ $ret['version'] = ord($data[0]);
+ $ret['type'] = ord($data[1]);
+ $ret['requestId'] = (ord($data[2]) << 8) + ord($data[3]);
+ $ret['contentLength'] = (ord($data[4]) << 8) + ord($data[5]);
+ $ret['paddingLength'] = ord($data[6]);
+ $ret['reserved'] = ord($data[7]);
return $ret;
}
// Reset timeout
$this->set_ms_timeout($this->_readWriteTimeout);
- switch (ord($resp['content']{4})) {
+ switch (ord($resp['content'][4])) {
case self::CANT_MPX_CONN:
throw new \Exception('This app can\'t multiplex [CANT_MPX_CONN]');
break;
--FILE--
<?php
$string = "foobar";
-var_dump($string{0}{0}[0][0]);
+var_dump($string[0][0][0][0]);
?>
--EXPECT--
string(1) "f"
--FILE--
<?php
$string = "foobar";
-var_dump(isset($string{0}{0}[0][0]));
+var_dump(isset($string[0][0][0][0]));
?>
--EXPECT--
bool(true)
--TEST--
testing the behavior of string offsets
---INI--
-error_reporting=E_ALL | E_DEPRECATED
--FILE--
<?php
$string = "foobar";
+const FOO = "BAR"[0];
+var_dump(FOO);
var_dump($string[0]);
var_dump($string[1]);
var_dump(isset($string[0]));
var_dump(isset($string[0][0]));
var_dump($string["foo"]);
var_dump(isset($string["foo"]["bar"]));
-var_dump($string{0});
+
+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}));
+var_dump(isset($string{0}{0})); // 2 notices
var_dump($string{"foo"});
-var_dump(isset($string{"foo"}{"bar"}));
+var_dump(isset($string{"foo"}{"bar"})); // 2 notices
?>
--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) "f"
string(1) "o"
bool(true)
Warning: Illegal string offset 'foo' in %s line %d
string(1) "f"
bool(false)
-string(1) "f"
+string(1) "B"
+array(1) {
+ [0]=>
+ string(1) "f"
+}
string(1) "o"
bool(true)
bool(true)