File: new_not_allowed_class_constant.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (18 lines) | stat: -rw-r--r-- 631 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
--TEST--
New not allowed in class constant
--FILE--
<?php

// New in class constants (and static properties) brings up evaluation order questions: When
// should the (potentially side-effecting) new expression be evaluated? Evaluating it when the
// class is declared would break references to classes that are declared later in the same
// file. On the other hand, the current lazy evaluation of initializers is somewhat ill-defined
// when we start considering side-effecting expressions.

class Test {
    const X = new stdClass;
}

?>
--EXPECTF--
Fatal error: New expressions are not supported in this context in %s on line %d