You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
I only tried to reproduce the examples given in the StrictPHP readme.
Here is my code:
// index.php<?phprequire __DIR__.'/../vendor/autoload.php';
\StrictPhp\StrictPhpKernel::bootstrap([
'debug' => true,
// change this if you use this tool on multiple projects:'cacheDir' => sys_get_temp_dir(),
'includePaths' => [
__DIR__,
],
]);
$obj = new limetec\Test();
$obj->dummyReturn(2);
// separate file Test.php<?phpnamespace limetec;
classTest {
/** * @return string */publicfunctiondummyReturn ($value) {
return$value;
}
}
I get the following error:
PHP Warning: array_map(): An error occurred while invoking the map callback in /home/jan/PhpstormProjects/strictphptest/vendor/roave/strict-php/src/StrictPhp/TypeChecker/ApplyTypeChecks.php on line 79
When I call $obj->dummyReturn("2") everything works fine.
Am I doing something wrong? I would have expected a more readable exception message.
The text was updated successfully, but these errors were encountered:
@janwalther the exception messages should actually be nicer, but that's not scheduled for 1.0 yet (probably going to be 2.0).
If we manage to restrict StrictPhp to PHP 7.0+ only, then we can redesign the type checkers to actually throw TypeError instances, so that would look better.
Sadly, array_map() behaves weirdly by implicitly try-catching around a exceptions (and throwing warning, sigh).
If you look further in the stack, you'll see the actual failure (currently a stupid throw new Exception('nope'))
I could introduce a new InvalidTypeException (which extends \ErrorException to be compatible with the current implementation) and give more readable exception messages instead of "nope". Are you interested?
Instead of array_map you could use a foreach loop and wrap the try-catch around this. Or is this not possible in this case?
I could introduce a new InvalidTypeException (which extends \ErrorException to be compatible with the current implementation) and give more readable exception messages instead of "nope". Are you interested?
It's more interesting to see what we can do with PHP7 throwable types (you can experiment with that)
Instead of array_map you could use a foreach loop and wrap the try-catch around this. Or is this not possible in this case?
I only tried to reproduce the examples given in the StrictPHP readme.
Here is my code:
I get the following error:
When I call $obj->dummyReturn("2") everything works fine.
Am I doing something wrong? I would have expected a more readable exception message.
The text was updated successfully, but these errors were encountered: