Note: Unlike other object-oriented programming languages, in PHP, a class cannot use the final modifier for a property variable.
If you want to declare a property as a constant, you can use the const keyword and there is no need to prefix the variable name with a dollar sign or use the access permission modifier. Constant means that although the variable can be accessed, the value of the variable cannot be modified. For example, the following code declares the constant attribute con_var:
Copy the code The code is as follows:
class Foo{
const con_var="The value of a constant attribute cannot be modified
";
public function method_a(){
echo (self::con_var);
}
}
echo(Foo::con_var);
$myFoo=new Foo();
echo ($myFoo->method_a());
?>
Constant attributes cannot be accessed using objects, but can only be accessed using classes. Within the class body, you can use "self::constant name", and outside the class body, you can use "classname::constant". name".
http://www.bkjia.com/PHPjc/327490.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327490.htmlTechArticleNote: Unlike other object-oriented programming languages, in PHP, a class cannot use final for a certain attribute variable. modifier. If you want to declare a property as a constant, you can use the const keyword...