Assign default property value : Class Property : Class PHP Source Code


PHP Source Code » Class » Class Property »

 

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";
?>


           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Class
» Class Property