Declaring 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 area of the circle. Const constants are used,
Note The method used, similar to the static variable.
Public final function Areaofcircular ($r) {
return $r * $r * self::P i;
}
Public final function Max ($a, $b) {
Return $a > $b? $a: $b;
}
Public function SETPI ($a) {
Self::P i = 3.1415;
}
}
echo Math::P i;
?>
Parse error:parse Error in e:phpprojectstest.php tutorial on line 17
Declaring 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 area of the circle. Const constants are used,
Note The method used, similar to the static variable.
Public final function Areaofcircular ($r) {
return $r * $r * self::P i;
}
Public final function Max ($a, $b) {
Return $a > $b? $a: $b;
}
}
echo Math::P i;
?>
The const defined constants in PHP5 are different from the methods that define variables, and do not require a $ modifier. Const PI = 3.14; That's all you can do.
Constant names that are defined with const are generally capitalized, which is a convention that is true in any language.
If you define a constant that consists of multiple words, use the _ connection, which is also the Convention.
For example, max_mumber such a naming method. A good naming method is what programmers must pay attention to.
A constant in a class is used like a static variable, except that its value cannot be changed. We use the class name:: Constant name to invoke this constant.
http://www.bkjia.com/PHPjc/444958.html www.bkjia.com true http://www.bkjia.com/PHPjc/444958.html techarticle ?//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 area of the circle. Using the CO NST constant,/...