<?php
class P{
public $foo;
}
class C extends P {
public $lol;
public function getFields()
{
var_dump(array_keys(get_class_vars(get_class(self))));
return array_keys(get_class_vars(__CLASS__));
}
}
$c = new C();
var_dump($c->getFields());
Fatal error: Uncaught Error: Undefined constant "self" in /in/NcEJ5:12
Stack trace:
#0 /in/NcEJ5(18): C->getFields()
#1 {main}
thrown in /in/NcEJ5 on line 12
Process exited with code 255.
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Use of undefined constant self - assumed 'self' (this will throw an Error in a future version of PHP) in /in/NcEJ5 on line 12
Warning: get_class() expects parameter 1 to be object, string given in /in/NcEJ5 on line 12
Warning: array_keys() expects parameter 1 to be array, bool given in /in/NcEJ5 on line 12
NULL
array(2) {
[0]=>
string(3) "lol"
[1]=>
string(3) "foo"
}
Output for 7.2.0 - 7.2.33
Warning: Use of undefined constant self - assumed 'self' (this will throw an Error in a future version of PHP) in /in/NcEJ5 on line 12
Warning: get_class() expects parameter 1 to be object, string given in /in/NcEJ5 on line 12
Warning: array_keys() expects parameter 1 to be array, boolean given in /in/NcEJ5 on line 12
NULL
array(2) {
[0]=>
string(3) "lol"
[1]=>
string(3) "foo"
}
Notice: Use of undefined constant self - assumed 'self' in /in/NcEJ5 on line 12
Warning: get_class() expects parameter 1 to be object, string given in /in/NcEJ5 on line 12
Warning: array_keys() expects parameter 1 to be array, boolean given in /in/NcEJ5 on line 12
NULL
array(2) {
[0]=>
string(3) "lol"
[1]=>
string(3) "foo"
}
Notice: Use of undefined constant self - assumed 'self' in /in/NcEJ5 on line 12
Warning: array_keys(): The first argument should be an array in /in/NcEJ5 on line 12
NULL
array(2) {
[0]=>
string(3) "lol"
[1]=>
string(3) "foo"
}
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NcEJ5 on line 4
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NcEJ5 on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/NcEJ5 on line 4
Process exited with code 255.