{"id":15023532,"url":"https://github.com/liamja/defer","last_synced_at":"2026-04-06T04:33:23.710Z","repository":{"id":57014484,"uuid":"121973494","full_name":"liamja/defer","owner":"liamja","description":"PHP library to postpone the calling of a function or callable.","archived":false,"fork":false,"pushed_at":"2018-02-18T17:39:09.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-31T22:43:33.334Z","etag":null,"topics":["composer-library","composer-package","php","php5","php53","php54","php55","php56"],"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/liamja.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":"2018-02-18T17:28:06.000Z","updated_at":"2018-02-18T17:34:15.000Z","dependencies_parsed_at":"2022-08-22T09:30:34.049Z","dependency_job_id":null,"html_url":"https://github.com/liamja/defer","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/liamja/defer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamja%2Fdefer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamja%2Fdefer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamja%2Fdefer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamja%2Fdefer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liamja","download_url":"https://codeload.github.com/liamja/defer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liamja%2Fdefer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31460103,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T21:22:52.476Z","status":"online","status_checked_at":"2026-04-06T02:00:07.287Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["composer-library","composer-package","php","php5","php53","php54","php55","php56"],"created_at":"2024-09-24T19:59:09.578Z","updated_at":"2026-04-06T04:33:23.694Z","avatar_url":"https://github.com/liamja.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Defer\n\nPostpone the calling of a function or callable.\n\n\n## Why?\n\nFrom _Go by Example_:\n\n\u003e Defer is used to ensure that a function call is performed later in a program’s execution, usually for purposes of cleanup. \n\u003e `defer` is often used where e.g. `ensure` and `finally` would be used in other languages.\n\nCommon use cases are:\n* Cleaning up temporary files.\n* Closing network connections.\n* Closing database connections.\n\nComparing `defer` to `finally`, this implementation of `defer` will allow us to have better control over when our\ndeferred functions are called; we can decide when to start stacking deferred functions, and where to finally call them.\n\n\n## Examples\n\n### Usage\n\n```php\n// Create an instance of Defer.\n// When $defer falls out of scope, the deferred callables will be called in reverse order.\n$defer = new Defer;\n\n// Push your deferred tasks to the $defer object.\n$defer-\u003epush(function () {\n    echo \"I'm echoed last!\";\n});\n\n// As a convenience, you can also call $defer as a function\n$defer(function () {\n    echo \"I'm echoed second!\";\n});\n\necho \"I'm called first!\";\n```\n\n\n### Closing Resources\n\nDefer can be used for ensuring the closing of open files:\n\n```php\n$fp = fopen('/tmp/file', 'w');\n\n$defer(function () use ($fp) {\n   fclose($fp);\n});\n\nfwrite($fp, 'Some temporary data.');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliamja%2Fdefer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliamja%2Fdefer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliamja%2Fdefer/lists"}