Ejemplo n.º 1
0
echo $ivan->getId() . "\n";
echo $ivan->__get("name") . "\n";
echo $ivan->__get("id") . "\n";
$ivanSalary = $ivan->__get("salary") . "\n";
$ivanAge = $ivan->age . "\n";
// неявно вызывает функцию __get
echo "ivan has salary :" . $ivanSalary;
echo "ivan has age :" . $ivanAge;
$he = new Employee();
$hisResult = $he->work(true);
echo "Он работал весь день и результат: " . $hisResult . "\n";
$she = new Manager(10000000);
$herSalary = $she->salary;
echo "Она не работала весь день и ее зарплата: " . $herSalary . "\n";
$employees = array();
$department = new Department("IT", $employees, $she);
$she->hire($ivan);
$allEmployees = $department->getEmployees();
printAllEmployees($allEmployees);
$she->hire($he);
$allEmployees = $department->getEmployees();
printAllEmployees($allEmployees);
$she->fire($he);
$allEmployees = $department->getEmployees();
printAllEmployees($allEmployees);
?>

</body>
</html>
 
Ejemplo n.º 2
0
<?php

/**
 * Created by PhpStorm.
 * User: ET
 * Date: 7/5/2015
 * Time: 3:58 PM
 */
function __autoload($class)
{
    include_once $class . '.php';
}
$hr = new Department('Human Resources');
$e1 = new Employee('Jane Doe');
$e2 = new Employee('John Doe');
$hr->addEmployee($e1);
$hr->addEmployee($e2);
var_dump($hr->getEmployees());
unset($hr, $e1, $e2);