1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00
Files
archived-php-src/Zend/tests/constexpr/new_allowed.phpt
Nikita Popov 52d3d0d8d7 Add limited support for new in initializers
Add support for new expressions inside parameter default values,
static variable initializers, global constant initializers and
attribute arguments.

RFC: https://wiki.php.net/rfc/new_in_initializers

Closes GH-7153.
2021-07-13 14:03:20 +02:00

36 lines
496 B
PHP

--TEST--
Places where new is allowed
--FILE--
<?php
#[SomeAttribute(new stdClass)]
class Test {
public function __construct(
public $prop = new stdClass,
) {
var_dump($prop);
}
}
function test($param = new stdClass) {
static $var = new stdClass;
var_dump($param, $var);
}
const TEST = new stdClass;
new Test;
test();
var_dump(TEST);
?>
--EXPECT--
object(stdClass)#3 (0) {
}
object(stdClass)#2 (0) {
}
object(stdClass)#3 (0) {
}
object(stdClass)#1 (0) {
}