Created
March 7, 2016 14:29
-
-
Save chrisguitarguy/30ba1506b760af239b4d to your computer and use it in GitHub Desktop.
TIL you cannot give PHP's scalar typehints any default value other than `null`. Completely with a misleading error message.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function foo(boolean $hello=true) | |
{ | |
// ... | |
} | |
/* | |
local> php -l example.php | |
PHP Fatal error: Default value for parameters with a class type hint can only be NULL in t.php on line 3 | |
Fatal error: Default value for parameters with a class type hint can only be NULL in t.php on line 3 | |
Errors parsing example.php | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use bool, not boolean. Aliases are not supported. See the original RFC: https://wiki.php.net/rfc/scalar_type_hints_v5