{"id":20256227,"url":"https://github.com/hazardland/debug.php","last_synced_at":"2025-04-11T00:22:06.263Z","repository":{"id":62515112,"uuid":"54507806","full_name":"hazardland/debug.php","owner":"hazardland","description":"nice single function php variable debug with formatted html or colored command line output support","archived":false,"fork":false,"pushed_at":"2018-05-14T11:37:49.000Z","size":168,"stargazers_count":18,"open_issues_count":4,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T21:11:12.227Z","etag":null,"topics":["debugger-visualizer","php","sublime"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hazardland.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-03-22T20:49:54.000Z","updated_at":"2024-05-28T14:59:13.000Z","dependencies_parsed_at":"2022-11-02T13:03:22.622Z","dependency_job_id":null,"html_url":"https://github.com/hazardland/debug.php","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazardland%2Fdebug.php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazardland%2Fdebug.php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazardland%2Fdebug.php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazardland%2Fdebug.php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hazardland","download_url":"https://codeload.github.com/hazardland/debug.php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248084388,"owners_count":21045125,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debugger-visualizer","php","sublime"],"created_at":"2024-11-14T10:45:55.447Z","updated_at":"2025-04-11T00:22:06.242Z","avatar_url":"https://github.com/hazardland.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"function debug ($object)\r\n================\r\n\r\nfunction debug (mixed $object, string/boolean $title=null, boolean/string $plain=false, integer $limit=6)\r\n\r\n**debug** is a single function for visually analything / logging complex deep level objects and arrays.\r\n\r\nExample of debug call html output:\r\n\r\n![](./demo/php-debug.png)\r\n\r\nExample of cli mode output\r\n\r\n![](./demo/php-cli-debug.png)\r\n\r\nOr\r\n\r\n![](./demo/php-visually-debug-array.png)\r\n\r\nLet us have an example classes (check ./demo/demo.php)\r\n```php\r\n\tclass test1\r\n\t{\r\n\t\tpublic $string = \"Test string\";\r\n\t\tpublic $boolean = true;\r\n\t\tpublic $integer = 17;\r\n\t\tpublic $float = 9.99;\r\n\t\tpublic $array = array ('bob'=\u003e'alice',true=\u003efalse,1=\u003e5,2=\u003e1.4);\r\n\t\tpublic $object;\r\n\t}\r\n\r\n\tclass test2\r\n\t{\r\n\t\tpublic $another;\r\n\t}\r\n\r\n\tclass test3\r\n\t{\r\n\t\tpublic $string1 = \"3d level\";\r\n\t\tpublic $string2 = \"123\";\r\n\t\tpublic $complicated;\r\n\t}\r\n\r\n\tclass test4\r\n\t{\r\n\t\tpublic $enough = \"Level 4\";\r\n\t\tpublic $something = \"Thanks for the fish!\";\r\n\t}\r\n```\r\n\r\nAnd intialize them in a following manner:\r\n```php\r\n\t$test = new test1 ();\r\n\t$test-\u003eobject = new test2();\r\n\t$test-\u003eobject-\u003eanother = new test3 ();\r\n\t$test-\u003eobject-\u003eanother-\u003ecomplicated = new test4 ();\r\n```\r\n\r\nNow let us start debugging **$test1**. A simpliest call:\r\n```php\r\n\tdebug ($test);\r\n```\r\nWill output following:\r\n\r\n![](./demo/php-debug-object.png)\r\n\r\nNote 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:\r\n\r\n```php\r\n\tdebug ($test, true);\r\n```\r\nSo now we see hidden parts of our object by default\r\n\r\n![](./demo/php-debug-object-expand.png)\r\n\r\nPutting title on debug:\r\n```php\r\n\t$pi = 3.14159265359;\r\n\tdebug ($pi, \"hello this is pi\");\r\n```\r\n\r\n![](./demo/php-debug-pi.png)\r\n\r\nTo have both expanded and titled debug we should just put * symbol in the begining of title string like this:\r\n```php\r\n\t$hm = array (1=\u003earray(2=\u003earray(3=\u003earray(4=\u003earray(5=\u003earray(6=\u003earray(7=\u003earray(8=\u003e\"Last depth we created\"))))))));\r\n\tdebug ($hm, \"* A very complicated expanded array\");\r\n```\r\n\r\n![](./demo/php-visually-debug-array.png)\r\n\r\nOn 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.\r\n\r\n```php\r\ndebug ($hm, \"* More levels\", false, 10);\r\n```\r\n\r\n![](./demo/php-visually-debug-array-full.png)\r\n\r\nThird parameter is for plain text output if you pass *true*\r\n```php\r\ndebug ($test, \"Output something as plain text\", true);\r\n```\r\nIt will output something like following indented with 4 space tabs:\r\n\r\n```php\r\nOutput something as plain text\r\n-------------------\r\nstring : \"Test string\"\r\nboolean : true\r\ninteger : 17\r\nfloat : 9.99\r\narray (array)\r\n    bob : \"alice\"\r\n    1 : 5\r\n    2 : 1.4\r\nobject (test2)\r\n    another (test3)\r\n        string1 : \"3d level\"\r\n        string2 : \"123\"\r\n        complicated (test4)\r\n            enough : \"Level 4\"\r\n\r\n```\r\n\r\nTo log plain text output in file just pass file path as a third parameter\r\n```php\r\ndebug ($test, date('Y-m-d H:i:s').\": Save plain text to file \", \"./test.log\");\r\n```\r\n\r\n![](./demo/php-log-variable.png)\r\n\r\nAnd 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:\r\n\r\n![](./demo/php-debug-sublime-protocol.png)\r\n\r\nTo debug in error log use 'error_log' in 3d parameter:\r\n````PHP\r\n\tdebug ($_GET,'GET','error_log');\r\n````\r\nTo view error log nicely formated use:\r\n````\r\ntail -f error_log | grep --line-buffered \"\\n--\" | sed \"s/\\\\\\n/\\\\n/g\"\r\n````\r\nOr if you want all other error log messages:\r\n````\r\ntail -f error_log | sed \"s/\\\\\\n/\\\\n/g\"\r\n````","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazardland%2Fdebug.php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhazardland%2Fdebug.php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazardland%2Fdebug.php/lists"}