Comparison #0001
Source Document
<?php
error_reporting(E_ERROR);
class B {
/**
* @param string $p
* @return string
*/
function g($p) {
if (!$p) {
return null;
}
return $p;
}
}
class C extends B {
function f($p) {
return $this->$p[0];
}
/**
* @param int $p
* @return int
*/
function g($p) {
$this->p = $p;
$this->property = [42];
return $this->f($p);
}
}
print (new C)->g('property' . $undeclared_global) . "\n";
Analyses
phan-strict
Line | Column | Details |
---|---|---|
11 |
[warning] PhanTypeMismatchReturnProbablyReal Returning null of type null but g() is declared to return string (no real type) (the inferred real return type has nothing in common with the declared phpdoc return type) |
|
19 |
[warning] PhanCompatiblePHP7 Expression may not be PHP 7 compatible |
|
19 |
[warning] PhanTypeInvalidPropertyName Saw a dynamic usage of an instance property with a name of type int but expected the name to be a string |
|
26 |
[warning] PhanParamSignatureMismatch Declaration of function g(int $p) : int should be compatible with function g(string $p) : string defined in samples/0001.php:9 (Expected int $p to have the same type as string $p or a supertype) |
|
27 |
[warning] PhanUndeclaredProperty Reference to undeclared property \C->p |
|
28 |
[warning] PhanUndeclaredProperty Reference to undeclared property \C->property |
|
34 |
[warning] PhanTypeMismatchArgument Argument 1 ($p) is ('property' . $undeclared_global) of type string but \C::g() takes int defined at samples/0001.php:26 |
|
34 |
[warning] PhanUndeclaredGlobalVariable Global variable $undeclared_global is undeclared |
|
Line | Column | Details |
phpstan-strict
Line | Column | Details |
---|---|---|
11 | 1 |
[error] return.type Method B::g() should return string but returns null. |
18 | 1 |
[error] missingType.return Method C::f() has no return type specified. |
18 | 1 |
[error] missingType.parameter Method C::f() has parameter $p with no type specified. |
26 | 1 |
[error] method.childParameterType Parameter #1 $p (int) of method C::g() should be compatible with parameter $p (string) of method B::g() |
26 | 1 |
[error] method.childReturnType Return type (int) of method C::g() should be compatible with return type (string) of method B::g() |
27 | 1 |
[error] property.notFound Access to an undefined property C::$p. |
28 | 1 |
[error] property.notFound Access to an undefined property C::$property. |
34 | 1 |
[error] argument.type Parameter #1 $p of method C::g() expects int, string given. |
34 | 1 |
[error] variable.undefined Variable $undeclared_global might not be defined. |
Line | Column | Details |
phpstan-loose
Line | Column | Details |
---|---|---|
27 | 1 |
[error] property.notFound Access to an undefined property C::$p. |
28 | 1 |
[error] property.notFound Access to an undefined property C::$property. |
psalm-strict
Line | Column | Details |
---|---|---|
7 | 16 |
[error] n/a InvalidNullableReturnType: The declared return type 'string' for B::g is not nullable, but 'null|string' contains null |
11 | 20 |
[error] n/a NullableReturnStatement: The declared return type 'string' for B::g is not nullable, but the function returns 'null' |
17 | 7 |
[error] n/a ClassMustBeFinal: Class C is never extended and is not part of the public API, and thus must be made final. |
18 | 14 |
[error] n/a MissingReturnType: Method C::f does not have a return type |
18 | 16 |
[error] n/a MissingParamType: Parameter $p has no provided type |
19 | 16 |
[error] n/a MixedArrayAccess: Cannot access array value on mixed variable |
24 | 16 |
[error] n/a ImplementedReturnTypeMismatch: The inherited return type 'string' for B::g is different to the implemented return type for C::g 'int' |
26 | 5 |
[error] n/a MissingOverrideAttribute: Method C::g should have the "Override" attribute |
26 | 16 |
[error] n/a ImplementedParamTypeMismatch: Argument 1 of C::g has wrong type 'int', expecting 'string' as defined by B::g |
27 | 9 |
[error] n/a UndefinedThisPropertyAssignment: Instance property C::$p is not defined |
28 | 9 |
[error] n/a UndefinedThisPropertyAssignment: Instance property C::$property is not defined |
29 | 16 |
[error] n/a MixedReturnStatement: Could not infer a return type |
34 | 18 |
[error] n/a InvalidArgument: Argument 1 of C::g expects int, but string provided |
34 | 31 |
[error] n/a UndefinedGlobalVariable: Cannot find referenced variable $undeclared_global in global scope |
34 | 31 |
[error] n/a MixedOperand: Right operand cannot be mixed |
Line | Column | Details |
psalm-loose
Line | Column | Details |
---|---|---|
26 | 5 |
[error] n/a MissingOverrideAttribute: Method C::g should have the "Override" attribute |
34 | 31 |
[error] n/a UndefinedGlobalVariable: Cannot find referenced variable $undeclared_global in global scope |