{"id":19325412,"url":"https://github.com/krypt0nn/php-ndbg","last_synced_at":"2026-06-13T02:32:14.598Z","repository":{"id":57009448,"uuid":"391634406","full_name":"krypt0nn/php-ndbg","owner":"krypt0nn","description":"PHP 5+ library to create debuggable code with native support without any extensions","archived":false,"fork":false,"pushed_at":"2021-08-01T14:57:40.000Z","size":18,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-06T06:43:36.138Z","etag":null,"topics":["debugging","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krypt0nn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-01T13:27:00.000Z","updated_at":"2021-08-02T14:20:13.000Z","dependencies_parsed_at":"2022-08-21T13:10:16.296Z","dependency_job_id":null,"html_url":"https://github.com/krypt0nn/php-ndbg","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/krypt0nn%2Fphp-ndbg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krypt0nn%2Fphp-ndbg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krypt0nn%2Fphp-ndbg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krypt0nn%2Fphp-ndbg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krypt0nn","download_url":"https://codeload.github.com/krypt0nn/php-ndbg/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240427326,"owners_count":19799471,"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":["debugging","php"],"created_at":"2024-11-10T02:09:59.195Z","updated_at":"2026-06-13T02:32:09.579Z","avatar_url":"https://github.com/krypt0nn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e🚀 php-ndbg\u003c/h1\u003e\n\n**PHP Native Debug** is a library that gives you ability to generate native debugging code from original one\n\n## Installation\n\n```\ncomposer require krypt0nn/php-ndbg\n```\n\n## Principle of work\n\nThe main idea is to add callbacks everywhere in code where the variables changes its values. For example\n\nOriginal one\n\n```php\n\u003c?php\n\n$var = 10;\n```\n\nDebuggable one\n\n```php\n\u003c?php\n\n$var = 10;\nvar_changed ('var', 10);\n```\n\nAnd define function `var_changed` somewhere above, like\n\n```php\n\u003c?php\n\nfunction var_changed ($name, $value)\n{\n    echo \"$name = $value\\n\";\n}\n```\n\nSo we'll see if some variables in code will change\n\n## Usage\n\nAn usage example you can find in `test` directory. There we have `test_file.php` that is the file we want to debug. File `test.php` will call `Ndbg\\Debugger::apply` method for this file and save it as `test_file_applied.php` with `debug_file.php` as the file with a debugging callback\n\nThis library has only one method: `Ndbg\\Debugger::apply(string $code, string $debug_file): string`. `$code` is the code you want to debug, `$debug_file` is debug file, of course, and this function will return debuggable code\n\nDebug file is a file with this structure:\n\n```php\n\u003c?php\n\nreturn function ($temp_name, $params)\n{\n    // this callback will be called when\n    // debuggable script will start\n\n    return function ($variable, $value, $params) use ($temp_name)\n    {\n        // this callback will be called every time\n        // when some variable will be changed\n    };\n};\n```\n\n`$temp_name` is a parameter that is containing, as you can guess, temporary name which is using as an \"empty\" variables value and `$GLOBALS` index for debugger data storing\n\n`$variable` and `$value` is parameters that tell you the name of the variable and its new value\n\nAnd `$params` contains array of some information about place where this callback was called\n\n```php\n[\n    'globals'   =\u003e $GLOBALS,\n    'line'      =\u003e __LINE__,\n    'file'      =\u003e __FILE__,\n    'function ' =\u003e __FUNCTION__,\n    'class'     =\u003e __CLASS__,\n    'method'    =\u003e __METHOD__,\n    'namespace' =\u003e __NAMESPACE__\n]\n```\n\nAnd if some constant will contain empty string as a value (like callback was called from a function without class and there `__CLASS__` will be `''` (an empty string)) - it will be replaced as null value\n\nSo an example debug file will looks like\n\n```php\n\u003c?php\n\nreturn function ($temp_name, $params)\n{\n    echo 'Ran file '. $params['file'] . PHP_EOL;\n\n    return function ($variable, $value, $params) use ($temp_name)\n    {\n        if ($params['function'] !== null)\n            echo 'Ran function '. $params['function'] .\n                 ' at line '. $params['line'] . PHP_EOL;\n    };\n};\n```\n\n\u003cbr\u003e\n\nAuthor: [Nikita Podvirnyy](https://vk.com/technomindlp)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrypt0nn%2Fphp-ndbg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrypt0nn%2Fphp-ndbg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrypt0nn%2Fphp-ndbg/lists"}