{"action":"created","issue":{"url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/1092","repository_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer","labels_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/1092/labels{/name}","comments_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/1092/comments","events_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/1092/events","html_url":"https://github.com/squizlabs/PHP_CodeSniffer/issues/1092","id":168233477,"number":1092,"title":"PEAR.Functions.ValidDefaultValueshould not flag type hinted methods with a NULL default argument","user":{"login":"SJrX","id":1916599,"avatar_url":"https://avatars.githubusercontent.com/u/1916599?v=3","gravatar_id":"","url":"https://api.github.com/users/SJrX","html_url":"https://github.com/SJrX","followers_url":"https://api.github.com/users/SJrX/followers","following_url":"https://api.github.com/users/SJrX/following{/other_user}","gists_url":"https://api.github.com/users/SJrX/gists{/gist_id}","starred_url":"https://api.github.com/users/SJrX/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SJrX/subscriptions","organizations_url":"https://api.github.com/users/SJrX/orgs","repos_url":"https://api.github.com/users/SJrX/repos","events_url":"https://api.github.com/users/SJrX/events{/privacy}","received_events_url":"https://api.github.com/users/SJrX/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/labels/Bug","name":"Bug","color":"e11d21"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":11,"created_at":"2016-07-29T01:42:13Z","updated_at":"2016-08-02T06:40:37Z","closed_at":"2016-08-02T00:44:21Z","body":"> Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected. Consider the following code snippet:\r\n> ...\r\n> To specify a type declaration, the type name should be added before the parameter name. The declaration can be made to accept NULL values if the default value of the parameter is set to NULL.\r\n\r\nhttp://php.net/manual/en/functions.arguments.php\r\n\r\nUnfortunately this leads to = null on a type hinted object having a double meaning as explained in this RFC https://wiki.php.net/rfc/nullable_types\r\n\r\n>This existing behavior is not changed by this RFC. The new nullable type feature offers a subset of the functionality of = null with both making a parameter nullable but only = null making a parameter optional and have a default value:\r\n\r\nUnfortunately the manual is vague and doesn't really make a distinction.  But using the PHP 7.1 RFC syntax a method like:\r\n\r\nfoo(Animal $animal = null, Car $car)\r\n\r\nhas the semantics of foo(?Animal $animal, Car $car)\r\n\r\nThat is the ability to not specify the parameter (i.e., use the default) is lost, but you are permitted to pass null objects still. This can be verified using reflection and checking the number of parameters, vs number of required parameters.\r\n\r\nI believe that this rule should specifically exclude the case where an argument is type hinted and has a default argument of null."},"comment":{"url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/comments/236814299","html_url":"https://github.com/squizlabs/PHP_CodeSniffer/issues/1092#issuecomment-236814299","issue_url":"https://api.github.com/repos/squizlabs/PHP_CodeSniffer/issues/1092","id":236814299,"user":{"login":"aik099","id":1277526,"avatar_url":"https://avatars.githubusercontent.com/u/1277526?v=3","gravatar_id":"","url":"https://api.github.com/users/aik099","html_url":"https://github.com/aik099","followers_url":"https://api.github.com/users/aik099/followers","following_url":"https://api.github.com/users/aik099/following{/other_user}","gists_url":"https://api.github.com/users/aik099/gists{/gist_id}","starred_url":"https://api.github.com/users/aik099/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aik099/subscriptions","organizations_url":"https://api.github.com/users/aik099/orgs","repos_url":"https://api.github.com/users/aik099/repos","events_url":"https://api.github.com/users/aik099/events{/privacy}","received_events_url":"https://api.github.com/users/aik099/received_events","type":"User","site_admin":false},"created_at":"2016-08-02T06:40:37Z","updated_at":"2016-08-02T06:40:37Z","body":"@gsherwood , which function declarations won't be reported as error after the fix:\r\n\r\n1. `function foo_default(Bar $bar = null) {}`\r\n2. `function foo_default(Bar $bar = null, $required) {}`\r\n\r\n?"}}
{"actor":{"display_login":"aik099"}}