Voting

: max(zero, zero)?
(Example: nine)

The Note You're Voting On

Sumon Mahmud (Abu Taleb)
3 years ago
define('MYKEY', 'The value is from outside of class');
class Abc{
   
    const MAX = 10;    

    public function __construct(){
        define('TEST', 'hello world! '); // using define function in class constructor
    }
    public function getOutput(){
        echo TEST . MYKEY . PHP_EOL; // accessing constants from outside of class
    }
}

$obj = new Abc();  // define function will call
$obj->getOutput(); // hello world! The value is from outside of class

echo Abc::MAX . PHP_EOL; // 10 - accessing constant using scope resolution

echo TEST; // hello world!  Because the constants is defined while constructor call

<< Back to user notes page

To Top