亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Why can PHP directly call non-static methods of a class through ::?
滿天的星座
滿天的星座 2017-06-10 09:47:28
0
7
653

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??

滿天的星座
滿天的星座

reply all(7)
大家講道理

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

Deprecated: Non-static method Demo::testing() should not be called statically in test.php on line 11

testing

某草草

Although this can be used, it is not recommended.

習(xí)慣沉默

php7.0 can be written like this, but php5.6 definitely cannot. It can also be written as self::testing

大家講道理

__callStatic()

學(xué)習(xí)ing

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template