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