예제 #1
0
        $this->employeeid = $employeeid;
    }
    function getEmployeeID()
    {
        return $this->employeeid;
    }
    // 为$tiecolor 定义一个设置方法和一个获取方法
    function setTieColor($tiecolor)
    {
        $this->tiecolor = $tiecolor;
    }
    function getTieColor()
    {
        return $this->tiecolor;
    }
}
// 新建一个Corporae_Drone对象
$drone1 = new Corporate_Drone();
// 设置$dronel的employeeid属性
$drone1->setEmployeeID("12345");
// 设置$drone1的tiecolor属性
$drone1->setTieColor("red");
// 克隆$drone1对象
$drone2 = clone $drone1;
// 设置$drone2的employeeid属性
$drone2->setEmployeeID("67890");
// 输出$drone1 和 $drone2 的employeeid属性
printf("Drone1 employeeID: %d<br/>", $drone1->getEmployeeID());
printf("Drone1 tiecolor: %s<br/>", $drone1->getTieColor());
printf("Drone2 employeeID: %d<br/>", $drone2->getEmployeeID());
printf("Drone2 tiecolor: %s<br/>", $drone2->getTieColor());
예제 #2
0
        $this->employeeid = $employeeid;
    }
    function getEmployeeID()
    {
        return $this->employeeid;
    }
    // Define a setter and getter for $tiecolor
    function setTiecolor($tiecolor)
    {
        $this->tiecolor = $tiecolor;
    }
    function getTiecolor()
    {
        return $this->tiecolor;
    }
}
// Create new Corporate_Drone object
$drone1 = new Corporate_Drone();
// Set the $drone1 employeeid member
$drone1->setEmployeeID("12345");
// Set the $drone1 tiecolor member
$drone1->setTiecolor("red");
// Clone the $drone1 object
$drone2 = clone $drone1;
// Set the $drone2 employeeid member
$drone2->setEmployeeID("67890");
// Output the $drone1 and $drone2 employeeid members
echo "Drone1 employeeID: " . $drone1->getEmployeeID() . "<br />";
echo "Drone1 tie color: " . $drone1->getTiecolor() . "<br />";
echo "Drone2 employeeID: " . $drone2->getEmployeeID() . "<br />";
echo "Drone2 tie color: " . $drone2->getTiecolor() . "<br />";