Php has two types of class attributes: Class constants and class static variables. These two types are easy to cause confusion.
Like static class methods and class instance methods, static class attributes and instance attributes cannot be redefined (with the same name), but static attributes can have the same name as class constants.
<? Php class test {const constvar = 'Hello world'; static $ staticvar = 'Hello world'; function getStaticvar () {return self ::$ staticvar ;}} $ obj = new test (); echo test: constvar // output 'Hello world' echo test: staticvar // error. You must add $ before staticvar to access the table, echo test: $ staticvar // output 'Hello world' $ str = 'test'; echo $ str:: $ staticvar // error. The class name cannot use the variable dynamic echo $ str: constvar // the cause of the error is the same as above // The class name has a variable When you are in an uncertain (dynamic) state, you can only use the following method to convert class variables $ obj2 = new $ str (); echo $ obj2-> getStaticvar ();?> <? Phpclass test {const constvar = 'Hello world'; static $ staticvar = 'Hello world'; function getStaticvar () {return self: $ staticvar ;}} $ obj = new test (); echo test: constvar // output 'Hello world' echo test: staticvar // error. You must add $ before staticvar to access the table, echo test: $ staticvar // output 'Hello world' $ str = 'test'; echo $ str:: $ staticvar // error. The class name cannot use the variable dynamic echo $ str: constvar // the cause of the error is the same as above // There is a variable in the class name that is in uncertainty (dynamic) status The response class variable $ obj2 = new $ str (); echo $ obj2-> getStaticvar ();?>