<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
class foo {
static public function test() {
var_dump(get_called_class());
}
public function testTwo() {
var_dump(get_called_class());
}
}
class bar extends foo {
}
class abc {
function test() {
foo::test();
bar::test();
}
function testTwo() {
foo::testTwo();
bar::testTwo();
}
}
echo "basic\n";
foo::test();
bar::test();
echo "basic without static declaration\n";
foo::testTwo();
bar::testTwo();
echo "in a class\n";
$abc = new abc();
$abc->test();
echo "in a class without static declaration\n";
$abc->testTwo();
basic
string(3) "foo"
string(3) "bar"
basic without static declaration
Fatal error: Uncaught Error: Non-static method foo::testTwo() cannot be called statically in /in/57N9u:35
Stack trace:
#0 {main}
thrown in /in/57N9u on line 35
Process exited with code 255.
basic
string(3) "foo"
string(3) "bar"
basic without static declaration
string(3) "foo"
string(3) "bar"
in a class
string(3) "foo"
string(3) "bar"
in a class without static declaration
string(3) "foo"
string(3) "bar"
basic
string(3) "foo"
string(3) "bar"
basic without static declaration
string(3) "foo"
string(3) "bar"
in a class
string(3) "foo"
string(3) "bar"
in a class without static declaration
string(3) "abc"
string(3) "abc"
basic
Fatal error: Call to undefined function get_called_class() in /in/57N9u on line 7
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/57N9u on line 6
Process exited with code 255.
Parse error: parse error, unexpected T_STATIC, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/57N9u on line 6
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/57N9u on line 6
Process exited with code 255.