PHP const


The const keyword is defined inside the class, not the usual define function.

grammar:

const constant = "value";

example:

class Person {
     // Define constants
     const country = "England";

     public function myCountry() {
         // Internal access constants
         echo "I ".self::country. "Person <br />";
     }
}

// Output constants
echo Person::country. "<br />";

// access method
$p1 = new Person();
$p1->myCountry();

Run the example output:

England
I am British

Once a constant value is defined, it can not be changed in the program.




Copyright 2014-2017 by DeveloperTut.com. All Rights Reserved.
TwitterGoogle+Facebook