-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,79 +90,125 @@ public function getStatusCode() | |
return $this->statusCode; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setStatusCode($code) | ||
{ | ||
$this->statusCode = $code; | ||
|
||
return $this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
} | ||
|
||
public function getHeaders() | ||
{ | ||
return $this->headers; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setHeaders(array $headers) | ||
{ | ||
$this->headers = $headers; | ||
|
||
return $this; | ||
} | ||
|
||
public function getClass() | ||
{ | ||
return $this->class; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setClass($class) | ||
{ | ||
$this->class = $class; | ||
$this->class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class; | ||
|
||
return $this; | ||
} | ||
|
||
public function getFile() | ||
{ | ||
return $this->file; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setFile($file) | ||
{ | ||
$this->file = $file; | ||
|
||
return $this; | ||
} | ||
|
||
public function getLine() | ||
{ | ||
return $this->line; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setLine($line) | ||
{ | ||
$this->line = $line; | ||
|
||
return $this; | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
return $this->message; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes we do, and this is handled: the result will be just |
||
}, $message); | ||
} | ||
|
||
$this->message = $message; | ||
|
||
return $this; | ||
} | ||
|
||
public function getCode() | ||
{ | ||
return $this->code; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setCode($code) | ||
{ | ||
$this->code = $code; | ||
|
||
return $this; | ||
} | ||
|
||
public function getPrevious() | ||
{ | ||
return $this->previous; | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setPrevious(self $previous) | ||
{ | ||
$this->previous = $previous; | ||
|
||
return $this; | ||
} | ||
|
||
public function getAllPrevious() | ||
|
@@ -191,11 +237,14 @@ public function setTraceFromException(\Exception $exception) | |
$this->setTraceFromThrowable($exception); | ||
} | ||
|
||
public function setTraceFromThrowable(\Throwable $throwable): void | ||
public function setTraceFromThrowable(\Throwable $throwable) | ||
{ | ||
$this->setTrace($throwable->getTrace(), $throwable->getFile(), $throwable->getLine()); | ||
return $this->setTrace($throwable->getTrace(), $throwable->getFile(), $throwable->getLine()); | ||
} | ||
|
||
/** | ||
* @return $this | ||
*/ | ||
public function setTrace($trace, $file, $line) | ||
{ | ||
$this->trace = array(); | ||
|
@@ -229,6 +278,8 @@ public function setTrace($trace, $file, $line) | |
'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : array(), | ||
); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
private function flattenArgs($args, $level = 0, &$count = 0) | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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 😃Uh oh!
There was an error while loading. Please reload this page.
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... :))