<?php
const A = 1;
const B = A * 2;
class C {
const THREE = TWO + 1;
const ONE_THIRD = A / self::THREE;
const SENTENCE = 'The value of THREE is '.self::THREE;
public function f($a = A + self::THREE) {
return $a;
}
}
echo (new C)->f()."\n";
echo C::SENTENCE;
?>
Fatal error: Uncaught Error: Undefined constant "TWO" in /in/YL9SG:6
Stack trace:
#0 /in/YL9SG(15): [constant expression]()
#1 {main}
thrown in /in/YL9SG on line 6
Process exited with code 255.
Fatal error: Uncaught Error: Undefined constant "TWO" in /in/YL9SG:15
Stack trace:
#0 {main}
thrown in /in/YL9SG on line 15
Process exited with code 255.
Warning: Use of undefined constant TWO - assumed 'TWO' (this will throw an Error in a future version of PHP) in /in/YL9SG on line 15
Warning: A non-numeric value encountered in /in/YL9SG on line 15
2
The value of THREE is 1
Output for 7.1.0 - 7.1.33
Notice: Use of undefined constant TWO - assumed 'TWO' in /in/YL9SG on line 15
Warning: A non-numeric value encountered in /in/YL9SG on line 15
2
The value of THREE is 1
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33
Notice: Use of undefined constant TWO - assumed 'TWO' in /in/YL9SG on line 15
2
The value of THREE is 1