Skip to content

Instantly share code, notes, and snippets.

@chrisguitarguy
Created March 7, 2016 14:29
Show Gist options
  • Select an option

  • Save chrisguitarguy/30ba1506b760af239b4d to your computer and use it in GitHub Desktop.

Select an option

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.
<?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
*/
@nyamsprod

Copy link
Copy Markdown

https://3v4l.org/OiNiO <- still fails on HHVM but that's another issue 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment