-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] Fixed dumping of terminated generator #21542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
lyrixx
commented
Feb 6, 2017
Q | A |
---|---|
Branch? | 2.8 |
Bug fix? | yes |
New feature? | no |
BC breaks? | no |
Deprecations? | no |
Tests pass? | yes |
Fixed tickets | - |
License | MIT |
Doc PR | - |
try { | ||
$reflectionGenerator = new \ReflectionGenerator($c); | ||
} catch (\Exception $e) { | ||
return $a; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add a virtual prop that says closed: true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Added.
@@ -99,28 +110,28 @@ public static function castReflectionGenerator(\ReflectionGenerator $c, array $a | |||
if ($c->getThis()) { | |||
$a[$prefix.'this'] = new CutStub($c->getThis()); | |||
} | |||
$x = $c->getFunction(); | |||
$function = $c->getFunction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff irrelevant for review
@@ -76,7 +76,18 @@ public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested) | |||
|
|||
public static function castGenerator(\Generator $c, array $a, Stub $stub, $isNested) | |||
{ | |||
return class_exists('ReflectionGenerator', false) ? self::castReflectionGenerator(new \ReflectionGenerator($c), $a, $stub, $isNested) : $a; | |||
if (!class_exists('ReflectionGenerator', false)) { | |||
return $a; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closed: true/false
virtual prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can I know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call ->valid()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not because it alters the generator. That's why I used the try catch method and not ->valid()
.
3ce2bf1
to
c5094a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// Cannot create ReflectionGenerator based on a terminated Generator | ||
try { | ||
$reflectionGenerator = new \ReflectionGenerator($c); | ||
} catch (\Exception $e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I confirm that an Exception
is thrown here, even-though I'd personally have expected a ReflectionException
ping @jpauli.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been fixed as part of PHP 7.2 in php/php-src@ed4216c
Thank you @lyrixx. |
This PR was merged into the 2.8 branch. Discussion ---------- [VarDumper] Fixed dumping of terminated generator | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- c5094a0 [VarDumper] Fixed dumping of terminated generator