Question

I've been using xdebug to debug and understand code in php projects for a while now, and have sometimes come into situations where it's been unclear what's going on inside of PHP.

Is it possible to set xdebug or gdb up so that i can trace into actual php builtin functions?

Was it helpful?

Solution

If you are using a macosx, solaris or recent freebsd system you can throw a little dtrace at it. It can come in handy for those all too numerous "WTF is PHP doing?" moments.

OTHER TIPS

I doubt it, xdebug is intended for tracing your PHP code, not the internals. The internals are assumed to be bug-free (which obviously they aren't sometimes, but that's beyond the scope of xdebug).

You can always look at the PHP source if you want to know what the built-in functions do, but that's sometimes pretty hairy. The PHP manual docs have always served me well enough when I want to know what they'll do.

You can use gdb to trace in to the C-level code, provided you have php compiled with debug symbols. Have a look here for a start:

http://derickrethans.nl/phps_segmentation_faults_gdbfu.php

One way to test the output of the Zend engine, to peek inside at the opcodes, you can use Derick Rethan's VLD (Vulcan Logic Dissasembler), which also appears to be on PECL. Note: only works on *nix systems (see site for requirements).

Some examples of debugging these opcodes can be found on Sara Golemon's blog, in articles such as Understanding Opcodes and How long is a piece of string?.

There is also great Google Chrome extension PHP Console with php library that allows to:

  • See errors & exception in Chrome JavaScript console & in notification popups.
  • Dump any type variable.
  • Execute PHP code remotely.
  • Protect access by password.
  • Group console logs by request.
  • Jump to error file:line in your text editor.
  • Copy error/debug data to clipboard (for testers).

Recommend to everyone!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top