PHP constructors and static functions

后端 未结 4 1291
野性不改
野性不改 2021-02-12 20:06

I\'m a bit confused on how constructors work in PHP.

I have a class with a constructor which gets called when I instantiate a new object.

$foo = new Foo(         


        
4条回答
  •  长发绾君心
    2021-02-12 20:41

    I see nothing that replicates your question.

    See Demo: http://codepad.org/h2TMPYUV

    Code:

    class Foo {
        function __construct(){ 
            echo 'hi!';
        }
        static function bar(){
            return 'there';
        }
    }
    
    echo Foo::bar(); //output: "there"
    

提交回复
热议问题