3

I am building a DI factory and seem to be getting this error:

Fatal error: Default value for parameters with a class type hint can only be NULL in your code on line 70

Which is this line:

public function get(
        $foo, bool $func = false, array $params = array()
    ) {

It seems that if I remove the bool before the $func paramater, it works.

Although, how can I hint a type array but not a type boolean?

Any help would be appreciated.

Jaquarh
  • 6,493
  • 7
  • 34
  • 86
  • 1
    Whar PHP Version are you using? In PHP < 7 there is no typehint for boolean values. So the interpreter assumes `bool` is a classname – l-x Jul 03 '16 at 12:48
  • 5.6 I believe? That maybe the exact issue then @l-x – Jaquarh Jul 03 '16 at 12:50
  • Some reference for @l-x's comment: [Function arguments - Valid types](http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration.types) (Check `Minimum PHP version` column). And if your php version is really 5.6, you can see that `array` type hint is available since `5.1.0` – FirstOne Jul 03 '16 at 12:56
  • Appreciated, I'll just have to remove the hint type - I only use them for better practice anyway @FirstOne – Jaquarh Jul 03 '16 at 13:05

0 Answers0