Let’s summarize today.
. When the internal method of a class accesses attributes that have been declared as const and static, use the form of self::$name. Note that the declaration format of the const attribute is const PI=3.14, not const $PI=3.14
Copy the code The code is as follows:
class clss_a {
private static $name="static class_a";
const PI=3.14;
public $value;
public static function getName ()
{
return self::$name;
}
//This way of writing is wrong, static methods cannot access non-static properties
public static function getName2()
{
return self::$value;
}
public function getPI()
{
return self::PI;
}
}
Another point to note is that if a class method is static, the properties it accesses must also be static.
. When the internal method of a class accesses attributes that are not declared const or static, use the form $this->value ='class_a';.
http://www.bkjia.com/PHPjc/320765.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/320765.htmlTechArticleLet’s summarize today. . When the internal method of a class accesses attributes that have been declared as const and static, use the form of self::$name. Note that the declaration format of the const attribute is const PI=3.14, and...