borisrepl / boris

A tiny REPL for PHP
MIT License
2.15k stars 115 forks source link

Support strict types. #129

Open glennpratt opened 7 years ago

glennpratt commented 7 years ago

PHP projects I'm working on lately are adding:

declare(strict_types=1);

to the top of every file, but I don't know how or if it's possible to enable this in boris.

This isn't a huge issue assuming you test your code, but it's nice to have the same behavior for things I write in boris as the code I'm working on.

$ boris

[1] boris> declare(strict_types=1);
[2] boris> function foo(): int { return '123'; }
// NULL
[3] boris> foo();
// 123

$ php -r "declare(strict_types=1); function foo(): int { return '123'; }; foo();"

PHP Fatal error:  Uncaught TypeError: Return value of foo() must be of the type integer, string returned in Command line code:1
Stack trace:
#0 Command line code(1): foo()
#1 {main}
  thrown in Command line code on line 1