{"action":"created","issue":{"url":"https://api.github.com/repos/symfony/symfony/issues/14431","labels_url":"https://api.github.com/repos/symfony/symfony/issues/14431/labels{/name}","comments_url":"https://api.github.com/repos/symfony/symfony/issues/14431/comments","events_url":"https://api.github.com/repos/symfony/symfony/issues/14431/events","html_url":"https://github.com/symfony/symfony/pull/14431","id":69927256,"number":14431,"title":"[Console] Bind the closure (code) to the Command if possible","user":{"login":"lyrixx","id":408368,"avatar_url":"https://avatars.githubusercontent.com/u/408368?v=3","gravatar_id":"","url":"https://api.github.com/users/lyrixx","html_url":"https://github.com/lyrixx","followers_url":"https://api.github.com/users/lyrixx/followers","following_url":"https://api.github.com/users/lyrixx/following{/other_user}","gists_url":"https://api.github.com/users/lyrixx/gists{/gist_id}","starred_url":"https://api.github.com/users/lyrixx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyrixx/subscriptions","organizations_url":"https://api.github.com/users/lyrixx/orgs","repos_url":"https://api.github.com/users/lyrixx/repos","events_url":"https://api.github.com/users/lyrixx/events{/privacy}","received_events_url":"https://api.github.com/users/lyrixx/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/symfony/symfony/labels/Console","name":"Console","color":"DDDDDD"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-04-21T19:10:02Z","updated_at":"2015-04-22T09:02:26Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/symfony/symfony/pulls/14431","html_url":"https://github.com/symfony/symfony/pull/14431","diff_url":"https://github.com/symfony/symfony/pull/14431.diff","patch_url":"https://github.com/symfony/symfony/pull/14431.patch"},"body":"| Q             | A\r\n| ------------- | ---\r\n| Bug fix?      | no\r\n| New feature?  | yes\r\n| BC breaks?    | no\r\n| Deprecations? | no\r\n| Tests pass?   | yes\r\n| Fixed tickets | ~\r\n| License       | MIT\r\n| Doc PR        | ~\r\n    \r\n\r\nThis allow this kind of code:\r\n\r\n```php\r\n#!/usr/bin/env php\r\n<?php\r\n\r\nrequire __DIR__.'/vendor/autoload.php';\r\n\r\nuse Symfony\\Component\\Console\\Application;\r\nuse Symfony\\Component\\Console\\Command\\Command;\r\nuse Symfony\\Component\\Console\\Input\\InputInterface;\r\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\r\n\r\n$application = new Application();\r\n\r\n$application->add((new Command('process')))\r\n    ->setDescription('Play all other commands')\r\n    ->setCode(function (InputInterface $input, OutputInterface $output) use ($application) {\r\n        $application = $this->getApplication();\r\n        $help = $application->find('help');\r\n        $output->writeln($help->getHelp());\r\n    })\r\n;\r\n$application->run();\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/symfony/symfony/issues/comments/95083063","html_url":"https://github.com/symfony/symfony/pull/14431#issuecomment-95083063","issue_url":"https://api.github.com/repos/symfony/symfony/issues/14431","id":95083063,"user":{"login":"lyrixx","id":408368,"avatar_url":"https://avatars.githubusercontent.com/u/408368?v=3","gravatar_id":"","url":"https://api.github.com/users/lyrixx","html_url":"https://github.com/lyrixx","followers_url":"https://api.github.com/users/lyrixx/followers","following_url":"https://api.github.com/users/lyrixx/following{/other_user}","gists_url":"https://api.github.com/users/lyrixx/gists{/gist_id}","starred_url":"https://api.github.com/users/lyrixx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lyrixx/subscriptions","organizations_url":"https://api.github.com/users/lyrixx/orgs","repos_url":"https://api.github.com/users/lyrixx/repos","events_url":"https://api.github.com/users/lyrixx/events{/privacy}","received_events_url":"https://api.github.com/users/lyrixx/received_events","type":"User","site_admin":false},"created_at":"2015-04-22T09:02:26Z","updated_at":"2015-04-22T09:02:26Z","body":"> Is there a way to detect whether the closure was bound explicitly in PHP ?\r\n\r\nyes, http://php.net/manual/en/reflectionfunctionabstract.getclosurethis.php\r\n\r\n```\r\nif (PHP_VERSION_ID >= 50400 && $code instanceof \\Closure) {\r\n            $r = new \\ReflectionFunction($code);\r\n            if (null === $r->getClosureThis()) {\r\n                $code = \\Closure::bind($code, $this);\r\n            }\r\n        }\r\n```\r\n\r\nbut I'm not able to unbind a closure in tests ... (even if the doc says it's possible)"}}