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

Stack trace order is backwards #2044

Closed
mindplay-dk opened this Issue Jan 21, 2016 · 4 comments

Comments

3 participants
@mindplay-dk
Copy link

mindplay-dk commented Jan 21, 2016

The order in which stack traces are displayed by php-unit is backwards compared with php's own error and exception stack traces - for example, error and exception stack traces look like this in php 7.0:

$ php -r "function foo() { throw new RuntimeException; } function bar() { foo(); } function baz() { bar(); } baz();"
PHP Fatal error:  Uncaught RuntimeException in Command line code:1
Stack trace:
#0 Command line code(1): foo()
#1 Command line code(1): bar()
#2 Command line code(1): baz()
#3 {main}
  thrown in Command line code on line 1

Fatal error: Uncaught RuntimeException in Command line code:1
Stack trace:
#0 Command line code(1): foo()
#1 Command line code(1): bar()
#2 Command line code(1): baz()
#3 {main}
  thrown in Command line code on line 1

Having to "switch modes" and figure out the order is very confusing - during a normal day, you see php error or exception stack traces, stack-traces from JavaScript consoles (Chrome, Node, etc.) and maybe stack-traces from other languages (like Java or C#) all of which are backwards compared with php-unit's stack traces.

Given that stack traces generated by php itself (as well as by most other languages) are displayed head-first, I suggest reversing the stack trace print-outs for consistency with, well, everything else.

Note that I'm aware that the stack trace order is consistent with that of xdebug. However, it too is inconsistent with php itself, as is clear from the second print-out on this page, where you actually see two stack-tracks in opposing order on screen at the same time. I have reported that issue against xdebug as well.

While you can argue in favor of one direction or the other, those arguments, in my opinion, are nowhere near as important as mere consistency - the mental switch required to read stack traces in opposing orders costs time. Even if you don't care about being consistent with other languages, it's tough to argue for inconsistency with php itself, and probably with JS, which most PHP developers use too.

@mindplay-dk

This comment has been minimized.

Copy link

mindplay-dk commented Feb 8, 2016

@sebastianbergmann any thoughts on this?

@derickr doesn't feel like fixing it, but I'm hoping maybe you feel differently - and that he might change his mind, if you decide to correct php-unit.

This inconsistency is hugely distracting, and it doesn't get better with experience. I wish everyone (php-unit, codeception, xdebug) would just agree on what a stack trace looks like and stick with it. Aligning with php itself would seem like the natural thing to do.

If you don't feel like doing the work either, let me know if you'd accept a PR...

@stof

This comment has been minimized.

Copy link
Contributor

stof commented Feb 16, 2016

The order of linked exceptions is also weird: PHPUnit displays the wrapped previous exception before displaying the exception itself

@sebastianbergmann

This comment has been minimized.

Copy link
Owner

sebastianbergmann commented Feb 16, 2016

All of this is very weird. I'd rather completely remove the filtering of exceptions then try to fix and/or change this, though.

@sebastianbergmann

This comment has been minimized.

Copy link
Owner

sebastianbergmann commented Feb 22, 2016

Closed in favor of #2089.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment