-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Improve support for anonymous classes #28218
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
@@ -753,12 +753,20 @@ protected function doRenderException(\Exception $e, OutputInterface $output) | |||
do { | |||
$message = trim($e->getMessage()); | |||
if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { | |||
$title = sprintf(' [%s%s] ', \get_class($e), 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : ''); | |||
$class = \get_class($e); | |||
$class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class; |
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'm curious about \0
, I know it represents a null byte, but it's the first time I see it in PHP code.
Does it improve perf or something like that? 🤔
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.
You cannot print a null char using null
as this would result in an empty string 😃
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.
That's desired, see #28218 (comment) (or maybe you mean something else... :))
Nothing like that. It's just part of the generated class name for anonymous
classes.
|
Oh okay, thanks 👍 |
da351cd
to
6380b7d
Compare
@@ -142,6 +142,12 @@ public function getMessage() | |||
|
|||
public function setMessage($message) | |||
{ | |||
if (false !== strpos($message, "class@anonymous\0")) { | |||
$message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) { | |||
return \class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0]; |
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.
technically this can occur for anon. clases without a parent class.. do we care? Same for setClass
.
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.
yes we do, and this is handled: the result will be just @anonymous
, as the VarDumper component already does.
@@ -518,21 +524,25 @@ public function handleException($exception, array $error = null) | |||
$handlerException = null; | |||
|
|||
if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) { | |||
if (false !== strpos($message = $exception->getMessage(), "class@anonymous\0")) { | |||
($message = new FlattenException())->setMessage($message); |
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.
naming the temporary variable $message
here looks weird, as it does not contain the message.
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.
Fixed by making FlattenException
fluent.
6380b7d
to
466b24a
Compare
466b24a
to
e41ced2
Compare
This PR was merged into the 4.2-dev branch. Discussion ---------- Improve support for anonymous classes | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Before:  After:  Same in other places, e.g. Console failures. Commits ------- e41ced2 Improve support for anonymous classes
public function setStatusCode($code) | ||
{ | ||
$this->statusCode = $code; | ||
|
||
return $this; |
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.
Do we really need fluent interface here?
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.
We don't need it. It still makes it easier to use the class.
Before:

After:

Same in other places, e.g. Console failures.