在PHP中以任何方式访问FOREACH之外的YIELD KEY?

Is there a way to access the KEY of the YIELD or it is acceptable only through foreach loop?

function foo()
{
    yield 'bar' => 'baz';
}

$foo = foo();
foreach ($foo as $key => $val)
    echo $key; // output: bar


$foo = foo();
echo key($foo->current()); //Warning:  key() expects parameter 1 to be array, string given

Generators implement the Iterator interface, so $foo->key() what you are looking for.