self:: vs className:: inside static className methods in PHP

前端 未结 2 1579
别跟我提以往
别跟我提以往 2021-02-07 02:52

I guess there may not be any difference but personal preference, but when reading various PHP code I come across both ways to access the methods class.

What is

2条回答
  •  不思量自难忘°
    2021-02-07 03:46

    With self you can use it within the class and with the "MyClass", as you have, you can reference it externally:

    $instance = new Myclass();
    $variable = $instance::$foo
    

提交回复
热议问题