{"action":"created","issue":{"url":"https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/issues/1645","labels_url":"https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/issues/1645/labels{/name}","comments_url":"https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/issues/1645/comments","events_url":"https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/issues/1645/events","html_url":"https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/1645","id":124543222,"number":1645,"title":"method_argument_default_value should be risky","user":{"login":"GrahamCampbell","id":2829600,"avatar_url":"https://avatars.githubusercontent.com/u/2829600?v=3","gravatar_id":"","url":"https://api.github.com/users/GrahamCampbell","html_url":"https://github.com/GrahamCampbell","followers_url":"https://api.github.com/users/GrahamCampbell/followers","following_url":"https://api.github.com/users/GrahamCampbell/following{/other_user}","gists_url":"https://api.github.com/users/GrahamCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/GrahamCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GrahamCampbell/subscriptions","organizations_url":"https://api.github.com/users/GrahamCampbell/orgs","repos_url":"https://api.github.com/users/GrahamCampbell/repos","events_url":"https://api.github.com/users/GrahamCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/GrahamCampbell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-01-01T12:30:33Z","updated_at":"2016-01-01T17:00:28Z","closed_at":null,"body":"The only way to allow a nullable scalar typehint is to add `null` as a default value.\r\n\r\nConsider the following code:\r\n\r\n```php\r\n<?php declare(strict_types=1);\r\n\r\nfunction foo(string $foo = null, array $bar)\r\n{\r\n    var_dump($foo, $bar);\r\n}\r\n\r\nfoo(null, [123]);\r\n```\r\n\r\nIt executes like this: https://3v4l.org/tGHmi.\r\n\r\n```\r\nNULL\r\narray(1) {\r\n  [0]=>\r\n  int(123)\r\n}\r\n```\r\n\r\nNow, this code will end up getting fixed to:\r\n\r\n```php\r\n<?php declare(strict_types=1);\r\n\r\nfunction foo(string $foo, array $bar)\r\n{\r\n    var_dump($foo, $bar);\r\n}\r\n\r\nfoo(null, [123]);\r\n```\r\n\r\nWhich now executes like this: https://3v4l.org/gqSgE.\r\n\r\n```\r\nFatal error: Uncaught TypeError: Argument 1 passed to foo() must be of the type string, null given, called in /in/gqSgE on line 8 and defined in /in/gqSgE:3\r\nStack trace:\r\n#0 /in/gqSgE(8): foo(NULL, Array)\r\n#1 {main}\r\n  thrown in /in/gqSgE on line 3\r\n```\r\nAs you can see, the fixer broke the code."},"comment":{"url":"https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/issues/comments/168317156","html_url":"https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/1645#issuecomment-168317156","issue_url":"https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/issues/1645","id":168317156,"user":{"login":"GrahamCampbell","id":2829600,"avatar_url":"https://avatars.githubusercontent.com/u/2829600?v=3","gravatar_id":"","url":"https://api.github.com/users/GrahamCampbell","html_url":"https://github.com/GrahamCampbell","followers_url":"https://api.github.com/users/GrahamCampbell/followers","following_url":"https://api.github.com/users/GrahamCampbell/following{/other_user}","gists_url":"https://api.github.com/users/GrahamCampbell/gists{/gist_id}","starred_url":"https://api.github.com/users/GrahamCampbell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GrahamCampbell/subscriptions","organizations_url":"https://api.github.com/users/GrahamCampbell/orgs","repos_url":"https://api.github.com/users/GrahamCampbell/repos","events_url":"https://api.github.com/users/GrahamCampbell/events{/privacy}","received_events_url":"https://api.github.com/users/GrahamCampbell/received_events","type":"User","site_admin":false},"created_at":"2016-01-01T17:00:28Z","updated_at":"2016-01-01T17:00:28Z","body":"For reference:\r\n\r\n```php\r\n>>> $tester = app(StyleCI\\Fixer\\ConfigTester::class);                                                                                                                                        => StyleCI\\Fixer\\ConfigTester {#953}\r\n>>> $sample = '<?php declare(strict_types=1);                                                                                                                                                function foo(string $foo = null, array $bar)                                                                                                                                                 {                                                                                                                                                                                                var_dump($foo, $bar);                                                                                                                                                                    }                                                                                                                                                                                            foo(null, [123]);';\r\n=> \"\"\"\r\n   <?php declare(strict_types=1);\\n\r\n   function foo(string $foo = null, array $bar)\\n\r\n   {\\n\r\n       var_dump($foo, $bar);\\n\r\n   }\\n\r\n   foo(null, [123]);\r\n   \"\"\"\r\n>>> $tester->analyze($sample)->sample();                                                                                                                                                     => \"\"\"\r\n   <?php\\n\r\n   \\n\r\n   declare(strict_types=1);\\n\r\n   function foo(string $foo = null, array $bar)\\n\r\n   {\\n\r\n       var_dump($foo, $bar);\\n\r\n   }\\n\r\n   foo(null, [123]);\\n\r\n   \"\"\"\r\n>>> $sample = '<?php declare(strict_types=1);                                                                                                                                                function foo($foo = null, array $bar)                                                                                                                                                        {                                                                                                                                                                                                var_dump($foo, $bar);                                                                                                                                                                    }                                                                                                                                                                                            foo(null, [123]);';\r\n=> \"\"\"\r\n   <?php declare(strict_types=1);\\n\r\n   function foo($foo = null, array $bar)\\n\r\n   {\\n\r\n       var_dump($foo, $bar);\\n\r\n   }\\n\r\n   foo(null, [123]);\r\n   \"\"\"\r\n>>> $tester->analyze($sample)->sample();                                                                                                                                                     => \"\"\"\r\n   <?php\\n\r\n   \\n\r\n   declare(strict_types=1);\\n\r\n   function foo($foo, array $bar)\\n\r\n   {\\n\r\n       var_dump($foo, $bar);\\n\r\n   }\\n\r\n   foo(null, [123]);\\n\r\n   \"\"\"\r\n>>>\r\n```"}}