Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

Pass class instance as parameter in php

Sun Oct 26, 2008 11:32 pm

Code:
<?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 );

?>




Post a reply
  Related Posts  to : Pass class instance as parameter in php
 pass parameter     -  
 A clone instance of class in php     -  
 Create object instance from class Name by reflection     -  
 class with constructor parameter     -  
 What exact mean by Object, Reference and Instance?     -  
 pass CompTIA LX0-101 & LX0-102 Exam quickly     -  
 All 4 CCNA semesters in power point pass?     -  
 pass parameters to main method args[] variables     -  
 How can I pass a PHP variable to a window.onload event funct     -  
 get url parameter     -  

Topic Tags

PHP OOP