Assign Default Property Value

 
    <?php
    class Employee {
        public $title       = "product";
        public $mainName    = "main";
        public $firstName   = "first";
        public $price       = 0;
 
        function getFullName() {
            return "{$this->firstName}".
                   " {$this->mainName}";
        }
    }$product1 = new Employee();
$product1->title = "title";
$product1->mainName  = "A";
$product1->firstName = "B";
$product1->price = 5.99;print "author: ".$product1->getFullName()."\n";
?>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.