Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. I check, compile and run every program. Contact me at: aviboots(AT)netvision.net.il

Hostgator - Save 50% Off Your New Optimized WordPress Hosting With Coupon: WDA50

BlueHost Web Hosting

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

Dedicated Hosting Superb Internet

simplilearn big data and analytics

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

Buy Cool Shirts

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


6,300 questions

8,938 answers

573 users

How to declare and use constants in class with PHP

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


8 views
asked Sep 6 by avibootz

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 by avibootz
edited Sep 7 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 by avibootz
...