code show as below:
<?php
class Demo
{
public function testing()
{
echo "testing\n";
}
}
Demo::testing();
php7.0 execution output:
$ php demo.php
testing
php5.6 execution output
$ php demo.php
PHP Strict Standards: Non-static method Demo::testing() should not be called statically in /home/runner/Code/funny/demo.php on line 11
testing
Is there such an operation?? What is the principle??
http://www.laruence.com/2012/...
Hahaha, thank you all for your answers. For the specific reasons, please read Brother Bird’s article above
If a class below version 5.6 directly calls methods and attributes without instantiation, the methods and attributes must be static methods, that is, if the Demo class directly calls the testing method, the test must be public static function testing() { }. Otherwise, an error will be reported.
I don’t know if there is no need to declare anything above 7.0
I saw it, but php-cli can execute it, but php-fpm still can’t
Although this can be used, it is not recommended.
php7.0 can be written like this, but php5.6 definitely cannot. It can also be written as self::testing
__callStatic()
It can be considered that the implementation of PHP is not rigorous.
If $this is not used in the non-static method, you can use:: to call it.