Call getter to get value for property : Getter Setter « Class « PHP






Call getter to get value for property

<?php
class Employee {
    public $title;
    public $lastName;
    public $firstName;
    public $price;
    
    function __construct( $title, $firstName, $mainName, $price ) { 
        $this->title     = $title;
        $this->firstName = $firstName;
        $this->lastName  = $mainName;
        $this->price     = $price;
    }

    function getFullName() {
        return "{$this->firstName}" . " {$this->lastName}";
    }
}

$product1 = new Employee("B", "B1", "B2", 5.99 );
$product2 = new Employee("A", "A1", "A2", 10.99 );
print "author: ".$product1->getFullName()."\n";
print "artist: ".$product2->getFullName()."\n";
?>


           
       








Related examples in the same category

1.Define getter and setter
2.Define and call getter method