TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.1 KiB
64 lines
1.1 KiB
--TEST--
|
|
Symfony Ldap pattern: iterator_to_array without keys cached by coalesce assignment
|
|
--FILE--
|
|
<?php
|
|
class SymfonyLdapEntryCollection implements IteratorAggregate
|
|
{
|
|
private ?array $entries = null;
|
|
public int $iterations = 0;
|
|
|
|
public function __construct(private array $source)
|
|
{
|
|
}
|
|
|
|
public function getIterator(): Traversable
|
|
{
|
|
++$this->iterations;
|
|
|
|
return new ArrayIterator($this->source);
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return $this->entries ??= iterator_to_array($this->getIterator(), false);
|
|
}
|
|
}
|
|
|
|
function main(): void
|
|
{
|
|
$collection = new SymfonyLdapEntryCollection([
|
|
'uid' => ['alice'],
|
|
'mail' => ['alice@example.com'],
|
|
]);
|
|
|
|
var_dump($collection->toArray());
|
|
var_dump($collection->toArray());
|
|
var_dump($collection->iterations);
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
array(2) {
|
|
[0]=>
|
|
array(1) {
|
|
[0]=>
|
|
string(5) "alice"
|
|
}
|
|
[1]=>
|
|
array(1) {
|
|
[0]=>
|
|
string(17) "alice@example.com"
|
|
}
|
|
}
|
|
array(2) {
|
|
[0]=>
|
|
array(1) {
|
|
[0]=>
|
|
string(5) "alice"
|
|
}
|
|
[1]=>
|
|
array(1) {
|
|
[0]=>
|
|
string(17) "alice@example.com"
|
|
}
|
|
}
|
|
int(1)
|
|
|