<?php
/**
 * Kilde: http://devzone.zend.com/6622/a-new-type-of-php-part-2-scalar-types/
 *
 */

interface AddressInterface {
    public function 
getStreet() : string;
    public function 
getCity() : string;
    public function 
getState() : string;
    public function 
getZip() : string;
}

class 
Address implements AddressInterface {
    protected 
$street;
    protected 
$city;
    protected 
$state;
    protected 
$zip;

    public function 
__construct(string $streetstring $citystring $statestring $zip) {
        
$this->street $street;
        
$this->city $city;
        
$this->state $state;
        
$this->zip $zip;
    }
    public function 
getStreet() : string { return $this->street; }
    public function 
getCity() : string { return $this->city; }
    public function 
getState() : string { return $this->state; }
    public function 
getZip() : string { return $this->zip; }
}

class 
Employee {
    protected 
$id;
    protected 
$address;

    public function 
__construct(int $idAddressInterface $address) {
        
$this->id $id;
        
$this->address $address;
    }

    public function 
getId() : int {
        return 
$this->id;
    }

    public function 
getAddress() : AddressInterface {
        return 
$this->address;
    }
}

class 
EmployeeRepository {

    private 
$data = [];

    public function 
__construct() {
        
$this->data[123] = new Employee(123, new Address('123 Main St.''Chicago''IL''60614'));
        
$this->data[456] = new Employee(456, new Address('45 Hull St''Boston''MA''02113'));
    }

    public function 
findById(int $id) : Employee {
        if (!isset(
$this->data[$id])) {
            throw new 
InvalidArgumentException('No such Employee: ' $id);
        }
        return 
$this->data[$id];
    }
}

$r = new EmployeeRepository();

try {
    print 
$r->findById(123)->getAddress()->getStreet() . PHP_EOL;
    print 
$r->findById(789)->getAddress()->getStreet() . PHP_EOL;
}
catch (
InvalidArgumentException $e) {
    print 
$e->getMessage() . PHP_EOL;
}


?>