I wrote a small test scenario for testing mixed use of static and non-static methods. When calling a public method as a static method it generates a strict warning. That got me thinking that perhaps calling a static method as a public method would generate a similar warning, but it did not.
Is it ok to call static methods as a non-static method? Are there any consequences to doing so?
<?php
class TestS {
static function _testS() {
echo("Hello Static<br>\n");
// Strict warning: Non-static method TestS::_tS() should not be
// called statically in TestS::_tS()
self::_tS();
}
public function _tS() {
echo("tS<br>\n");
}
public function _testP() {
echo("Hello Public<br>\n");
self::_tP();
}
static function _tP() {
echo("tP<br>\n");
}
public function _testSP() {
$this->_tP();
}
}
$test = new TestS();
echo("///////////<br>\n");
$test->_testP();
echo("///////////<br>\n");
TestS::_testS();
echo("///////////<br>\n");
$test->_testSP();
echo("///////////<br>\n");