-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[VarDumper] Dump PHP+Twig code excerpts in backtraces #15838
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
c1104ca
to
730262d
Compare
4f3a2ac
to
2b4379b
Compare
36c164e
to
4b9b8d8
Compare
Tips: to get the same kind of output using debug_backtrace(), use: dump(['here' => new TraceStub(debug_backtrace())]); |
ccc4960
to
b959a87
Compare
b959a87
to
f051fbc
Compare
Rebased |
👍 |
} | ||
extract($frame->value); |
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.
shouldn't you prevent overwriting of variables here to avoid issues ?
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.
No need, overwritting $a could even be useful to some
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.
but this could also overwrite $frame
, which would break the following code
f051fbc
to
e10dc9b
Compare
Updated |
e10dc9b
to
89578f1
Compare
Thank you @nicolas-grekas. |
…(nicolas-grekas) This PR was merged into the 2.8 branch. Discussion ---------- [VarDumper] Dump PHP+Twig code excerpts in backtraces | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - ExceptionCaster::filterTrace() is deprecated and replaced by a more flexible backtrace processing that allows one to register casters for amending/changing dumped backtraces. This is especially useful for dumping source map information/excerpts (like e.g. twig template source). Here is a comparison generated with this code snippet (see also the expected output in testThrowingCaster): ```php namespace Symfony\Component\VarDumper\Caster; require 'vendor/autoload.php'; function bar() { return foo(); } function foo() { dump(new \Exception('baz')); } bar('aaaaarg'); ``` Before:  After:  Commits ------- 89578f1 [VarDumper] Dump PHP+Twig code excerpts in backtraces
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.
The filterTrace method is deprecated since version 2.8 and will be removed in 3.0. Use the castTraceStub method instead.
Can not understand how should I change them. I have this code:
$trace = $exception->getTrace();
ExceptionCaster::filterTrace($trace, false);
This code transforms $trace
variable from
[
[
'function' => '%methodName%',
'class' => '%FQCN%',
'type' => '->',
'args' => [/* ... */],
],
// ...
]
to this format:
[
[
'call' => '%FQCN%->%methodName%',
'file' => '',
],
// ...
]
How can I do the same by using ExceptionCaster::castTraceStub
? I'm tried to use It like this:
$trace = $exception->getTrace();
$trace = ExceptionCaster::castTraceStub(
new TraceStub($trace),
$trace,
new Stub(),
true
);
return $a; | ||
} | ||
$stub->class = ''; | ||
$stub->handle = 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.
Why we need a $stub
here? It does not pass by reference, just set 2 properties and that's all.
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.
@Aliance this is modifying an object. So it has an effect
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.
Ok, well then I'm not understanding smth. Can you answer my question above?
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.
Mb @nicolas-grekas can help me?
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.
Please open an issue, comments on commits are hard to track.
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.
ExceptionCaster::filterTrace() is deprecated and replaced by a more flexible backtrace processing that allows one to register casters for amending/changing dumped backtraces. This is especially useful for dumping source map information/excerpts (like e.g. twig template source).
Here is a comparison generated with this code snippet (see also the expected output in testThrowingCaster):
Before:

After:
