Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Hostgator 1 Penny

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,765 questions

10,845 answers

573 users

How to declare and use constants in class with PHP

2 Answers

0 votes
class ConstClass
{
    const PI = M_PI;
    const PI_2 = M_PI_2;
    const COST = 9.95;
}

$val = ConstClass::PI * ConstClass::PI_2 * ConstClass::COST;

echo $val;

 
/*
run: 
  
49.10128189542
  
*/    

 




answered Sep 6, 2017 by avibootz
edited Sep 7, 2017 by avibootz
0 votes
class ConstClass 
{
    const COST = 9.95;

    public function getCost($units) 
    {
         return self::COST * $units;
    }
}

$object = new ConstClass;

echo $object->getCost(10);

 
/*
run: 
  
99.5
  
*/                    

 




answered Sep 7, 2017 by avibootz
...