Pass class instance as parameter : Class Method : Class PHP Source Code


PHP Source Code » Class » Class Method »

 

Pass class instance as parameter



<?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}";
        }
    }
    
class EmployeeWriter {
    public function write$shopProduct ) {
        $str  = "{$shopProduct->title}: ";   
        $str .= $shopProduct->getFullName();
        $str .= " ({$shopProduct->price})n";
        print $str;
    }
}
$product1 = new Employee"Title""A""B"5.9 );
$writer = new EmployeeWriter();
$writer->write$product1 );

?>


           
       



HTML code for linking to this page:

Follow Navioo On Twitter

PHP Source Code

 Navioo Class
» Class Method