Skip to content

Commit 62d6a78

Browse files
committed
Add debug_var_dump for debugging.
1 parent 7073802 commit 62d6a78

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/debug_var_dump.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef DEBUG_VAR_DUMP_H
2+
#define DEBUG_VAR_DUMP_H
3+
extern "C" {
4+
#include <main/php.h>
5+
#include <ext/standard/php_var.h>
6+
}
7+
8+
/* Hack with PHP's buffering to bypass it and vardump directly to stderr. */
9+
static void debug_var_dump_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC) {
10+
// dump this right to stderr
11+
fwrite(output, 1, output_len, stderr);
12+
*handled_output = estrdup("");
13+
*handled_output_len = 0;
14+
}
15+
16+
static inline void debug_var_dump(zval *v TSRMLS_DC) {
17+
// first push a new buffer context
18+
php_output_start_internal("debug_var_dump", 14, debug_var_dump_handler, 64, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
19+
// now invoke var_dump
20+
php_var_dump(&v, 1 TSRMLS_CC);
21+
// now flush/pop the buffer context
22+
php_output_end(TSRMLS_C);
23+
}
24+
#endif

0 commit comments

Comments
 (0)