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.

Bug 262632 - No error on return different type than the method declaration wants to
Summary: No error on return different type than the method declaration wants to
Status: NEW
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Mysik
Depends on:
Reported: 2016-06-30 11:15 UTC by Christian Lenz
Modified: 2016-10-27 10:05 UTC (History)
0 users

See Also:
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description Christian Lenz 2016-06-30 11:15:42 UTC
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.


Comment 1 Tomas Mysik 2016-07-01 05:46:08 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.
Comment 2 Christian Lenz 2016-10-27 09:58:53 UTC
Same happens for function test(int $a) {};

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.
Comment 3 Christian Lenz 2016-10-27 09:59:27 UTC
I can understand the thing with the linter, maybe it is an option where you can add such checks for warnings and errors too.
Comment 4 Christian Lenz 2016-10-27 10:01:51 UTC
And here I have an other example for overriding a method:

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.
Comment 5 Christian Lenz 2016-10-27 10:05:33 UTC
Here you can see the warning:

<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 />