xref: /PHP-7.4/sapi/phpdbg/.phpdbginit (revision 37c329d7)
1##########################################################
2# .phpdbginit
3#
4# Lines starting with # are ignored
5# Code must start and end with <: and :> respectively
6##########################################################
7# Place initialization commands one per line
8##########################################################
9# exec sapi/phpdbg/test.php
10# set color prompt white-bold
11# set color notice green
12# set color error red
13
14##########################################################
15# Embedding code in .phpdbginit
16##########################################################
17<:
18/*
19* This embedded PHP is executed at init time
20*/
21
22/*
23* Functions defined and registered by init
24* will persist across cleans
25*/
26
27/*
28function my_debugging_function()
29{
30	var_dump(func_get_args());
31}
32*/
33
34/* phpdbg_break(PHPDBG_METHOD, "phpdbg::method"); */
35/* phpdbg_break(PHPDBG_FUNC, "my_global_function"); */
36/* phpdbg_break(PHPDBG_FILE, "/path/to/file.php:10"); */
37
38/*
39 If readline is loaded, you might want to setup completion:
40*/
41if (function_exists('readline_completion_function')) {
42	readline_completion_function(function(){
43		return array_merge(
44			get_defined_functions()['user'],
45			array_keys(get_defined_constants())
46		);
47	});
48}
49
50/*
51 Setting argv made trivial ...
52
53 argv 1 2 3 4
54 ^ set argv for next execution
55
56 argv
57 ^ unset argv for next execution
58
59*/
60function argv()
61{
62	$argv = func_get_args();
63
64	if (!$argv) {
65		$_SERVER['argv'] = array();
66		$_SERVER['argc'] = 0;
67		return;
68	}
69
70	$_SERVER['argv'] = array_merge
71	(
72		array("phpdbg"),
73		$argv
74	);
75	$_SERVER['argc'] = count($_SERVER['argv']);
76
77	return $_SERVER['argv'];
78}
79:>
80##########################################################
81# Now carry on initializing phpdbg ...
82##########################################################
83# R my_debugging_function
84# R argv
85
86##########################################################
87# PHP has many functions that might be useful
88# ... you choose ...
89##########################################################
90# R touch
91# R unlink
92# R scandir
93# R glob
94
95##########################################################
96# Remember: *you have access to the shell*
97##########################################################
98# The output of registered function calls is not,
99# by default, very pretty (unless you implement
100# and register a new implementation for phpdbg)
101# The output of shell commands will usually be more
102# readable on the console
103##########################################################
104# TLDR; if you have a good shell, use it ...
105##########################################################
106