1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
<?php declare(strict_types=1);
// Observer objects for the Zend/tests/list_keyed_evaluation_order.* tests
class StringCapable
{
private $name;
public function __construct(string $name) {
$this->name = $name;
}
public function __toString(): string {
echo "$this->name evaluated.", PHP_EOL;
return $this->name;
}
}
class Indexable implements ArrayAccess
{
private $array;
public function __construct(array $array) {
$this->array = $array;
}
public function offsetExists($offset): bool {
echo "Existence of offset $offset checked for.", PHP_EOL;
return isset($this->array[$offset]);
}
public function offsetUnset($offset): void {
unset($this->array[$offset]);
echo "Offset $offset removed.", PHP_EOL;
}
public function offsetGet($offset): mixed {
echo "Offset $offset retrieved.", PHP_EOL;
return $this->array[$offset];
}
public function offsetSet($offset, $value): void {
$this->array[$offset] = $value;
echo "Offset $offset set to $value.", PHP_EOL;
}
}
class IndexableRetrievable
{
private $label;
private $indexable;
public function __construct(string $label, Indexable $indexable) {
$this->label = $label;
$this->indexable = $indexable;
}
public function getIndexable(): Indexable {
echo "Indexable $this->label retrieved.", PHP_EOL;
return $this->indexable;
}
}
|