ReflectionGenerator example

public static function unsetClosureFileInfo(\Closure $c, array $a)
    {
        unset($a[Caster::PREFIX_VIRTUAL.'file']$a[Caster::PREFIX_VIRTUAL.'line']);

        return $a;
    }

    public static function castGenerator(\Generator $c, array $a, Stub $stub, bool $isNested): array
    {
        // Cannot create ReflectionGenerator based on a terminated Generator         try {
            $reflectionGenerator = new \ReflectionGenerator($c);
        } catch (\Exception) {
            $a[Caster::PREFIX_VIRTUAL.'closed'] = true;

            return $a;
        }

        return self::castReflectionGenerator($reflectionGenerator$a$stub$isNested);
    }

    /** * @return array */
EODUMP;

        $r = new \ReflectionGenerator($generator);
        $this->assertDumpMatchesFormat($expectedDump[$r$r->getExecutingGenerator()]);

        foreach ($generator as $v) {
        }

        $expectedDump = <<<'EODUMP' Generator { closed: true } EODUMP;
        $this->assertDumpMatchesFormat($expectedDump$generator);
    }
public static function unsetClosureFileInfo(\Closure $c, array $a)
    {
        unset($a[Caster::PREFIX_VIRTUAL.'file']$a[Caster::PREFIX_VIRTUAL.'line']);

        return $a;
    }

    public static function castGenerator(\Generator $c, array $a, Stub $stub, bool $isNested): array
    {
        // Cannot create ReflectionGenerator based on a terminated Generator         try {
            $reflectionGenerator = new \ReflectionGenerator($c);
        } catch (\Exception) {
            $a[Caster::PREFIX_VIRTUAL.'closed'] = true;

            return $a;
        }

        return self::castReflectionGenerator($reflectionGenerator$a$stub$isNested);
    }

    /** * @return array */
VarExporter::export($value);
        } finally {
            $this->assertDumpEquals(rtrim($expectedDump)$value);
        }
    }

    public static function provideFailingSerialization()
    {
        yield [hash_init('md5')];
        yield [new \ReflectionClass(\stdClass::class)];
        yield [(new \ReflectionFunction(function D): int {}))->getReturnType()];
        yield [new \ReflectionGenerator((function D) { yield 123; })())];
        yield [function D) {}];
        yield [function D) { yield 123; }];
        yield [new \SplFileInfo(__FILE__)];
        yield [$h = fopen(__FILE__, 'r')];
        yield [[$h]];

        $a = new class() {
        };

        yield [$a];

        
Home | Imprint | This part of the site doesn't use cookies.