This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
If you have this piece of code: function test($foo): int { return "t"; } I expect, as in java for example, an error or warning, that this shouldn't be possible, because the return type is int and I tried to return a string. Cheers Chris
It works the same way as in this example: /** * @return int */ function test($foo) { return "t"; } It means, no error in any of those cases. Moreover, if you run lint (php -l) on such a file, even PHP does not report any error. So, changing to enhancement. Thanks for reporting.
Same happens for function test(int $a) {}; Test("Test"); Should give an error that int is expected and not string. Such scalar types do not make any sense if you not check the types.
I can understand the thing with the linter, maybe it is an option where you can add such checks for warnings and errors too.
And here I have an other example for overriding a method: <?php class Test { function Tester(int $a, string $b) { echo "Tester"; } } class TestImpl extends Test { public function Tester($a, $b) { echo "Tester"; } } $testImpl = new TestImpl(); $testImpl->Tester(1, "t"); The method which overrides the other, should give error/warnings/hint (configurable) to show me that I missed the type and both types "should" be compatible with each other. So it's not a must have for that.
Here you can see the warning: http://sandbox.onlinephpfunctions.com/code/74103db5f2a736edf1ca64cddf3ec8165b71cb95 <br /> <b>Warning</b>: Declaration of TestImpl::Tester($a, $b) should be compatible with Test::Tester(int $a, string $b) in <b>[...][...]</b> on line <b>13</b><br /> Override