1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 16:22:37 +01:00
Files
archived-php-src/Zend/tests/varSyntax/newVariable.phpt
Christoph M. Becker bcf9d1e995 new_variable '{' expr '}' is deprecated as well
Curly brace syntax for accessing array elements and string offsets is
deprecated [1]; this should also be the case for respective `new`
expressions.

This issue has been reported by brzuchal@php.net.

[1] <https://wiki.php.net/rfc/deprecate_curly_braces_array_access>
2019-09-09 19:05:23 +02:00

41 lines
840 B
PHP

--TEST--
Variable as class name for new expression
--FILE--
<?php
$className = 'stdClass';
$array = ['className' => 'stdClass'];
$obj = (object) ['className' => 'stdClass'];
class Test {
public static $className = 'stdClass';
}
$test = 'Test';
$weird = [0 => (object) ['foo' => 'Test']];
var_dump(new $className);
var_dump(new $array['className']);
var_dump(new $array{'className'});
var_dump(new $obj->className);
var_dump(new Test::$className);
var_dump(new $test::$className);
var_dump(new $weird[0]->foo::$className);
?>
--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) {
}
object(stdClass)#%d (0) {
}
object(stdClass)#%d (0) {
}