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
Narrow down the return type of the Throwable::getTrace()
method
#914
Narrow down the return type of the Throwable::getTrace()
method
#914
Conversation
I like it. would this also be usefull for debug_backtrace() ? |
Done 😃 But I have a doubt, and I don't understand all the process to compute the backtrace found here: are the |
Answer to myself: I've found this test case where the function gen(): Generator
{
yield 1;
var_dump(debug_backtrace());
}
for ($gen = gen(); $gen->valid(); $gen->next()) {
$gen->current();
} |
Thanks! As you can see in the build failures, it might get annoying in some cases. Although technically true, a lot of existing code out there relies on the keys to always exist. Do you have some real-world examples where the keys do not exist? Thanks! |
Regarding the failures, I've already opened PRs to almost all involved projects to fix the problems so I expect the build to pass soon
I have the same feeling, however this is a clear error which will produce warnings/notices when accessing the undefined key, so I think it's appropriate for PHPStan to report it. Maybe this could be released in the next minor instead of a patch version to reduce the immediate impact of this change for all projects?
Actually it's pretty easy to imagine them by just looking at the description of each key in the PHP docs. In any case, any well written code should take into account that most of the keys don't always exist and I expect that the majority of the issues will be around the fact that not everyone is aware that |
|
Here's an example of how I could get some stacktrace frame where the set_exception_handler(function (Throwable $exception) {
var_dump($exception->getTrace());
});
class Foo
{
private $foo;
public function __toString()
{
return $this->foo;
}
}
sprintf('%s', new Foo()); At the moment I cannot came up with a test case with |
After some research, I found a test case in the PHP repo where set_exception_handler(function () {
ob_end_clean();
});
set_error_handler(function() {
var_dump(debug_backtrace());
throw new Exception();
});
$a['waa']; |
Okay, file and line are optional, but what about others? Can you get And can you do it in a try-catch instead of an exception handler? I need the modification to be practical and not academical, so it's not worthy to set the key as optional if it can never happen in real world. Can you also please link the PRs you opened here? Thanks. |
So, after looking again at the source code of PHP, I'm reasonably sure that there cannot be a stacktrace frame without the
rectorphp/rector-src#1648, nextras/orm#552 and sebastianbergmann/phpunit#4857 |
…sCheckCall()` method
@ondrejmirtes finally the CI passes and the PR is ready for review 🥳 |
This was probably a larger effort than you anticipated :) Thank you very much. I'll /cc you when someone complains about the new signature :) |
As per title, with this PR I'm narrowing down the array shape returned by the
Throwable::getTrace()
method (and its children classes of course). At the beginning I though that it was enough to change thefunctionMap.php
file, but the stub takes precedence so I had to edit both files