<?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
Compiling this script with KPHP will result in an error:
If
CandIdefined in different files (the usual case), this error is very confusion. It tells thatC::fhas some@paramfor non-existing parameter$x, but in fact it has no phpdoc (it also doesn't have$xparameter).We should either permit param names to mismatch as in PHP or give a better compilation error, like: