├── composer.json ├── debug.php ├── demo ├── demo.php ├── php-cli-debug.png ├── php-debug-object-expand.png ├── php-debug-object.png ├── php-debug-pi.png ├── php-debug-sublime-protocol.png ├── php-debug.png ├── php-log-variable.png ├── php-visually-debug-array-full.png ├── php-visually-debug-array.png └── test.log ├── pull.bat ├── push.bat └── readme.md /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hazardland/debug", 3 | "type": "library", 4 | "description": "php variable debug", 5 | "keywords": ["debug"], 6 | "homepage": "http://github.com/hazardland/debug.php", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "hazardland", 11 | "email": "hazardland@gmail.com", 12 | "homepage": "http://hazardland.com", 13 | "role": "Developer" 14 | } 15 | ], 16 | "require": 17 | { 18 | "php": ">=5.4.21" 19 | }, 20 | "autoload": { 21 | "files": ["debug.php"] 22 | } 23 | } -------------------------------------------------------------------------------- /debug.php: -------------------------------------------------------------------------------- 1 | \n"; 125 | $charset = true; 126 | } 127 | if ($level>$limit) 128 | { 129 | if ($plain) 130 | { 131 | return str_repeat(' ', 4*$level)."...\n"; 132 | } 133 | else 134 | { 135 | return "..."; 136 | } 137 | } 138 | if (is_object($object) || (is_array($object) && count($object)>0)) 139 | { 140 | foreach ($object as $key => $value) 141 | { 142 | if ($plain) 143 | { 144 | $result .= str_repeat(' ', 4*$level).$key; 145 | } 146 | else 147 | { 148 | if (is_array($object)) 149 | { 150 | $result .= "".$key.''; 151 | } 152 | else 153 | { 154 | $result .= ''.$key.''; 155 | } 156 | } 157 | if (is_object($value) || (is_array($value) && count($value)>0)) 158 | { 159 | if (is_object($value)) 160 | { 161 | if ($plain) 162 | { 163 | $result .= " (".get_class($value).")"; 164 | } 165 | else 166 | { 167 | $result .= " ".get_class($value).""; 168 | } 169 | } 170 | else 171 | { 172 | if ($plain) 173 | { 174 | $result .= " (array)"; 175 | } 176 | else 177 | { 178 | $result .= " array"; 179 | } 180 | } 181 | if ($plain) 182 | { 183 | $result .= "\n"; 184 | } 185 | else 186 | { 187 | $collapse = !($level+1<=1 || $title===true || (is_string($title) && substr($title,0,1)=='*')); 188 | $result .= "\n
"; 49 | debug ($test, "Output as plain text", true); 50 | echo ""; 51 | 52 | debug ($test, date('Y-m-d H:i:s').": Save plain text to file ", "./test.log"); 53 | 54 | debug ($test, "Limit level rendering to 1", false, 1); 55 | 56 | $pi = 3.14159265359; 57 | debug ($pi, "hello this is pi"); 58 | 59 | $hm = array (1=>array(2=>array(3=>array(4=>array(5=>array(6=>array(7=>array(8=>"Last depth we created")))))))); 60 | debug ($hm, "* A very complicated expanded array"); 61 | debug ($hm, "* More levels", false, 10); 62 | 63 | ?> -------------------------------------------------------------------------------- /demo/php-cli-debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-cli-debug.png -------------------------------------------------------------------------------- /demo/php-debug-object-expand.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-debug-object-expand.png -------------------------------------------------------------------------------- /demo/php-debug-object.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-debug-object.png -------------------------------------------------------------------------------- /demo/php-debug-pi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-debug-pi.png -------------------------------------------------------------------------------- /demo/php-debug-sublime-protocol.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-debug-sublime-protocol.png -------------------------------------------------------------------------------- /demo/php-debug.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-debug.png -------------------------------------------------------------------------------- /demo/php-log-variable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-log-variable.png -------------------------------------------------------------------------------- /demo/php-visually-debug-array-full.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-visually-debug-array-full.png -------------------------------------------------------------------------------- /demo/php-visually-debug-array.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hazardland/debug.php/892008458cdbab1c1f8f669e69cbd7164bfeb6a6/demo/php-visually-debug-array.png -------------------------------------------------------------------------------- /demo/test.log: -------------------------------------------------------------------------------- 1 | -------------------------------------- 2 | 2016-03-23 02:28:00: Save plain text to file 3 | -------------------------------------- 4 | string : "Test string" 5 | boolean : true 6 | integer : 17 7 | float : 9.99 8 | array (array) 9 | bob : "alice" 10 | 1 : 5 11 | 2 : 1.4 12 | object (test2) 13 | another (test3) 14 | string1 : "3d level" 15 | string2 : "123" 16 | complicated (test4) 17 | enough : "Level 4" 18 | something : "Thanks for the fish!" 19 | -------------------------------------- 20 | 2016-03-23 02:28:01: Save plain text to file 21 | -------------------------------------- 22 | string : "Test string" 23 | boolean : true 24 | integer : 17 25 | float : 9.99 26 | array (array) 27 | bob : "alice" 28 | 1 : 5 29 | 2 : 1.4 30 | object (test2) 31 | another (test3) 32 | string1 : "3d level" 33 | string2 : "123" 34 | complicated (test4) 35 | enough : "Level 4" 36 | something : "Thanks for the fish!" 37 | -------------------------------------- 38 | 2016-03-23 02:37:03: Save plain text to file 39 | -------------------------------------- 40 | string : "Test string" 41 | boolean : true 42 | integer : 17 43 | float : 9.99 44 | array (array) 45 | bob : "alice" 46 | 1 : 5 47 | 2 : 1.4 48 | object (test2) 49 | another (test3) 50 | string1 : "3d level" 51 | string2 : "123" 52 | complicated (test4) 53 | enough : "Level 4" 54 | something : "Thanks for the fish!" 55 | -------------------------------------- 56 | 2016-03-23 02:37:06: Save plain text to file 57 | -------------------------------------- 58 | string : "Test string" 59 | boolean : true 60 | integer : 17 61 | float : 9.99 62 | array (array) 63 | bob : "alice" 64 | 1 : 5 65 | 2 : 1.4 66 | object (test2) 67 | another (test3) 68 | string1 : "3d level" 69 | string2 : "123" 70 | complicated (test4) 71 | enough : "Level 4" 72 | something : "Thanks for the fish!" 73 | -------------------------------------- 74 | 2016-06-14 18:20:40: Save plain text to file 75 | -------------------------------------- 76 | string : "Test string" 77 | boolean : true 78 | integer : 17 79 | float : 9.99 80 | array (array) 81 | bob : "alice" 82 | 1 : 5 83 | 2 : 1.4 84 | object (test2) 85 | another (test3) 86 | string1 : "3d level" 87 | string2 : "123" 88 | complicated (test4) 89 | enough : "Level 4" 90 | something : "Thanks for the fish!" 91 | -------------------------------------------------------------------------------- /pull.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | git pull origin master -------------------------------------------------------------------------------- /push.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | IF %1.==. GOTO COMMENT 3 | git add * 4 | git commit -a -m %1 5 | git push origin master 6 | GOTO END 7 | :COMMENT 8 | echo no commit comment 9 | :END -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | function debug ($object) 2 | ================ 3 | 4 | function debug (mixed $object, string/boolean $title=null, boolean/string $plain=false, integer $limit=6) 5 | 6 | **debug** is a single function for visually analything / logging complex deep level objects and arrays. 7 | 8 | Example of debug call html output: 9 | 10 |  11 | 12 | Example of cli mode output 13 | 14 |  15 | 16 | Or 17 | 18 |  19 | 20 | Let us have an example classes (check ./demo/demo.php) 21 | ```php 22 | class test1 23 | { 24 | public $string = "Test string"; 25 | public $boolean = true; 26 | public $integer = 17; 27 | public $float = 9.99; 28 | public $array = array ('bob'=>'alice',true=>false,1=>5,2=>1.4); 29 | public $object; 30 | } 31 | 32 | class test2 33 | { 34 | public $another; 35 | } 36 | 37 | class test3 38 | { 39 | public $string1 = "3d level"; 40 | public $string2 = "123"; 41 | public $complicated; 42 | } 43 | 44 | class test4 45 | { 46 | public $enough = "Level 4"; 47 | public $something = "Thanks for the fish!"; 48 | } 49 | ``` 50 | 51 | And intialize them in a following manner: 52 | ```php 53 | $test = new test1 (); 54 | $test->object = new test2(); 55 | $test->object->another = new test3 (); 56 | $test->object->another->complicated = new test4 (); 57 | ``` 58 | 59 | Now let us start debugging **$test1**. A simpliest call: 60 | ```php 61 | debug ($test); 62 | ``` 63 | Will output following: 64 | 65 |  66 | 67 | Note that object of class *test3* is collapsed and only first property is visible you can unfold it by clicking + or you can just debug object with everything expanded by calling: 68 | 69 | ```php 70 | debug ($test, true); 71 | ``` 72 | So now we see hidden parts of our object by default 73 | 74 |  75 | 76 | Putting title on debug: 77 | ```php 78 | $pi = 3.14159265359; 79 | debug ($pi, "hello this is pi"); 80 | ``` 81 | 82 |  83 | 84 | To have both expanded and titled debug we should just put * symbol in the begining of title string like this: 85 | ```php 86 | $hm = array (1=>array(2=>array(3=>array(4=>array(5=>array(6=>array(7=>array(8=>"Last depth we created")))))))); 87 | debug ($hm, "* A very complicated expanded array"); 88 | ``` 89 | 90 |  91 | 92 | On a depth level 6 (considering starting level is 0) only ... is visible because of depth rendering limit which is by default 6. To unlock other levels we should incrase limit. 93 | 94 | ```php 95 | debug ($hm, "* More levels", false, 10); 96 | ``` 97 | 98 |  99 | 100 | Third parameter is for plain text output if you pass *true* 101 | ```php 102 | debug ($test, "Output something as plain text", true); 103 | ``` 104 | It will output something like following indented with 4 space tabs: 105 | 106 | ```php 107 | Output something as plain text 108 | ------------------- 109 | string : "Test string" 110 | boolean : true 111 | integer : 17 112 | float : 9.99 113 | array (array) 114 | bob : "alice" 115 | 1 : 5 116 | 2 : 1.4 117 | object (test2) 118 | another (test3) 119 | string1 : "3d level" 120 | string2 : "123" 121 | complicated (test4) 122 | enough : "Level 4" 123 | 124 | ``` 125 | 126 | To log plain text output in file just pass file path as a third parameter 127 | ```php 128 | debug ($test, date('Y-m-d H:i:s').": Save plain text to file ", "./test.log"); 129 | ``` 130 | 131 |  132 | 133 | And lastly if you are using subl-protocol plugin for sublime (https://github.com/thecotne/subl-protocol) you can unfold debug backtrace and with one click in browser jump on the specific file and line in sublime text editor: 134 | 135 |  136 | 137 | To debug in error log use 'error_log' in 3d parameter: 138 | ````PHP 139 | debug ($_GET,'GET','error_log'); 140 | ```` 141 | To view error log nicely formated use: 142 | ```` 143 | tail -f error_log | grep --line-buffered "\n--" | sed "s/\\\n/\\n/g" 144 | ```` 145 | Or if you want all other error log messages: 146 | ```` 147 | tail -f error_log | sed "s/\\\n/\\n/g" 148 | ```` --------------------------------------------------------------------------------