class t {
public function tt()
{
echo 1;
}
}
t::tt();
See?The non-static function can also be called at class level.So what’s different if I add a static keyword before public?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Except that, if you try to use
$thisin your method, like this :You’ll get a Fatal Error when calling the non-static method statically :
i.e. your example is a bit too simple, and doesn’t really correspond to a real-case 😉
Also note that your example should get you a strict warning (quoting) :
And it actually does (At least, with PHP 5.3) :
So : not that good 😉
Still, statically calling a non-static method doesnt’t look like any kind of good practice (which is probably why it raises a Strict warning), as static methods don’t have the same meaning than non-static ones : static methods do not reference any object, while non-static methods work on the instance of the class there’re called on.
Once again : even if PHP allows you to do something (Maybe for historical reasons — like compatibility with old versions), it doesn’t mean you should do it !