summaryrefslogtreecommitdiff
path: root/tutorials/initializing.md
blob: de01bb23fa0da4b7a2e66a78f7e8082192c85385 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
phpdbginit
==========
*Setting up your debugging session automatically*

By default, phpdbg looks for *.phpdbginit* in the current working directory, this location can be overrideen on the command line:

```
phpdbg -imy.phpdbginit
```

An init file should contain one command per line, any phpdbg command is supported during init.

In addition, *.phpdbginit* can contain embedded code, allowing, for example 

 - the setup of auto completion
 - the registration of functions
 - the acquisition and pre-compilation of code
 - bootstrapping a web application

It is common for C projects (PHP included) to include an init file for the GDB debugger; this would be a clever practice to adopt
for those distributing PHP library code.

The default .phpdbginit
=======================

We distribute the following init file by default, it should be copied to any directory you commonly execute in:

```
##########################################################
# .phpdbginit
#
# Lines starting with # are ignored
# Code must start and end with <: and :> respectively
##########################################################
# Place initialization commands one per line
##########################################################
# exec sapi/phpdbg/test.php

##########################################################
# Embedding code in .phpdbginit
##########################################################
<:
/*
 If readline is loaded, you might want to setup completion:
*/
if (function_exists('readline_completion_function')) {
	readline_completion_function(function(){
		return array_merge(
			get_defined_functions()['user'],
			array_keys(get_defined_constants())
		);
	});
}
:>
##########################################################
# Now carry on initializing phpdbg ...
##########################################################
# R my_debugging_function

##########################################################
# PHP has many functions that might be useful
# ... you choose ...
##########################################################
# R touch
# R unlink
# R scandir
# R glob

##########################################################
# Remember: *you have access to the shell*
##########################################################
# The output of registered function calls is not,
# by default, very pretty (unless you implement
# and register a new implementation for phpdbg)
# The output of shell commands will usually be more
# readable on the console
##########################################################
# TLDR; if you have a good shell, use it ...
##########################################################
```