Contributing Advent 17: Printing stacks
Anybody who is vaguely familiar with Xdebug probably has seen its glorious orange stack traces gracing their screens. In case you have not, they look like:
In this case, the tell_a_lie_and_hurt_you() function tried to call strlen() with incorrect arguments.
Xdebug overloads PHP's internal error handler to do this, but it is also possible to trigger stack traces yourself. You can of course use trigger_error(), but Xdebug also provides the xdebug_print_function_stack() function. Running xdebug_print_function_stack() instead of the erroneous strlen() results in:
As the documentation state, you can also provide your own message:
<?php
function tell_a_lie_and_hurt_you()
{
xdebug_print_function_stack("You have been rickrolled!");
}
Which then results in:
This was all good, and then my friend Rob asked:
hypothetically, how hard would it be to change xdebug_print_function_stack() so that it didn't output the filename and line number in the orange box?
Well, it didn't turn out to be very hard. Rob requested this feature because he was writing his own error handler. And with your own error handler it does not make a whole lot of sense to show where xdebug_print_function_stack() was called from. After my commit, you can now supply a second argument to xdebug_print_function_stack():
<?php
function tell_a_lie_and_hurt_you()
{
xdebug_print_function_stack("You have been rickrolled!", XDEBUG_STACK_NO_DESC);
}
Which then results in a stack trace without header:
This new feature will be part of Xdebug 2.3.
Life Line
Juvenile Ruff stretching out.
Taken at Titchwell March.
#photography #Birds #BirdPhotography #BirdsOfFediverse #NaturePhotography #wildlife #Norfolk
Specify road surfaces
Specify whether there are cycleways
Survey housenumbers
Specify path surfaces
Specify whether crosswalks have tactile paving
Specify whether pedestrian crossings have islands
Specify whether kerbs have tactile paving
Determine the heights of kerbs
Specify whether bicycles can be charged at charging stations
Specify whether roads have sidewalks
Created 2 entrances; Updated an apartments building
I walked 7.5km in 1h38m33s
A very well camouflaged Little Owl.
It's in a hole in a church tower, in a tiny village in North Norfolk.
#photography #Birds #BirdPhotography #BirdsOfFediverse #NaturePhotography #Norfolk
Survey postbox collection times
Survey housenumbers
Specify whether places take fees to visit
Survey shop types
Specify whether there are cycleways
Specify whether pedestrian crossings have islands
Determine the heights of kerbs
Specify whether traffic signals have tactile indications that it's safe to cross
Specify whether crosswalks have tactile paving
Specify whether kerbs have tactile paving
Specify drinking water types



Shortlink
This article has a short URL available: https://drck.me/adv1317-afc