PHP object-oriented constant in PHP5 .? Declare a final class MathclassMath {constPI3.14; publicfunction _ toString () {return this is the Math class .;} Here we write a method for calculating the circular area. The Const constant is used, // Declare a final class Math
Class Math {
Const PI = 3.14;
Public function _ toString (){
Return "this is the Math class. ";
}
// Here is a method for calculating the circular area. The Const constant is used,
// Pay attention to the method used, similar to static variables.
Public final function areaOfCircular ($ r ){
Return $ r * self: PI;
}
Public final function max ($ a, $ B ){
Return $ a> $ B? $ A: $ B;
}
Public function setPI ($ ){
Self: PI = 3.1415;
}
}
Echo Math: PI;
?>
Parse error: parse error in E: PHPProjectstest. php Tutorial on line 17
// Declare a final class Math
Class Math {
Const PI = 3.14;
Public function _ toString (){
Return "this is the Math class. ";
}
// Here is a method for calculating the circular area. The Const constant is used,
// Pay attention to the method used, similar to static variables.
Public final function areaOfCircular ($ r ){
Return $ r * self: PI;
}
Public final function max ($ a, $ B ){
Return $ a> $ B? $ A: $ B;
}
}
Echo Math: PI;
?>
In PHP5, constants defined by const are different from those defined by variables. you do not need to add a $ modifier. Const PI = 3.14; then you can.
The constant names defined by const are generally capitalized. this is a convention, as is true in any language.
If the defined constant is composed of multiple words and uses _ join, this is also the convention.
For example, MAX_MUMBER. A good naming method must be noticed by programmers.
Constants in a class are similar to static variables, but their values cannot be changed. We use the class name: constant name to call this constant.
Http://www.bkjia.com/PHPjc/444958.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444958.htmlTechArticle? // Declare a final class Math {const PI = 3.14; public function _ toString () {return this is the Math class .; } // Here is a method for calculating the circular area. The Const constant is used ,/...