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.
Summary: | No error on return different type than the method declaration wants to | ||
---|---|---|---|
Product: | php | Reporter: | Christian Lenz <chrizzly> |
Component: | Editor | Assignee: | Tomas Mysik <tmysik> |
Status: | NEW --- | ||
Severity: | normal | ||
Priority: | P3 | ||
Version: | 8.1 | ||
Hardware: | All | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: |
Description
Christian Lenz
2016-06-30 11:15:42 UTC
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 |