Skip to content

Confusing error for the method implementation with mismatching param name #42

@quasilyte

Description

@quasilyte
<?php

interface I {
    /** @param int $x */
    public function f($x);
}

class C implements I {
    public function f($y) { // Note: it's $y, not $x
        return $y + 1;
    }
}

$c = new C();
var_dump($c->f(10)); // prints 11 in PHP

Compiling this script with KPHP will result in an error:

Compilation error [gen by $KPHP_ROOT/compiler/pipes/prepare-function.cpp at 303]
In stage = [Prepare function]:
  [file = example.php]
  [function = C::f:9]
  [line = 9]
//   9:
@param for unexisting argument $x

Compilation terminated due to errors

If C and I defined in different files (the usual case), this error is very confusion. It tells that C::f has some @param for non-existing parameter $x, but in fact it has no phpdoc (it also doesn't have $x parameter).

We should either permit param names to mismatch as in PHP or give a better compilation error, like:

$y param name should be $x, as defined in the I interface

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions