2017-12-12 06:49:40 +01:00
# Issue types
### AbstractInstantiation
2018-11-15 21:44:13 +01:00
Emitted when an attempt is made to instantiate an abstract class:
2017-12-12 06:49:40 +01:00
```php
abstract class A {}
new A();
```
2019-04-26 00:02:19 +02:00
### ArgumentTypeCoercion
Emitted when calling a function with an argument which has a less specific type than the function expects
```php
class A {}
class B extends A {}
function takesA(A $a) : void {
takesB($a);
}
function takesB(B $b) : void {}
```
2017-12-12 06:49:40 +01:00
### AssignmentToVoid
Emitted when assigning from a function that returns `void` :
```php
function foo() : void {}
$a = foo();
```
2018-01-01 02:32:47 +01:00
### CircularReference
Emitted when a class references itself as one of its parents
```php
class A extends B {}
class B extends A {}
```
2018-01-29 06:39:21 +01:00
### ConflictingReferenceConstraint
Emitted when a by-ref variable is set in two different branches of an if to different types.
```php
class A {
/** @var int */
private $foo;
public function __construct(int & $foo) {
$this->foo = &$foo;
}
}
class B {
/** @var string */
private $bar;
public function __construct(string & $bar) {
$this->bar = &$bar;
}
}
if (rand(0, 1)) {
$v = 5;
$c = (new A($v)); // $v is constrained to an int
} else {
$v = "hello";
$c = (new B($v)); // $v is constrained to a string
}
$v = 8;
```
2017-12-12 06:49:40 +01:00
### ContinueOutsideLoop
Emitted when encountering a `continue` statement outside a loop context.
2018-01-29 06:39:21 +01:00
```php
$a = 5;
continue;
```
2017-12-12 06:49:40 +01:00
### DeprecatedClass
2018-01-29 06:39:21 +01:00
Emitted when referring to a deprecated class:
2017-12-12 06:49:40 +01:00
```php
/** @deprecated */
class A {}
new A();
```
2018-08-10 19:25:25 +02:00
### DeprecatedConstant
Emitted when referring to a deprecated constant:
```php
class A {
/** @deprecated */
const FOO = 'foo';
}
echo A::FOO;
```
2018-01-29 06:39:21 +01:00
### DeprecatedInterface
Emitted when referring to a deprecated interface
```php
/** @deprecated */
interface I {}
class A implements I {}
```
2017-12-12 06:49:40 +01:00
### DeprecatedMethod
Emitted when calling a deprecated method on a given class:
```php
class A {
/** @deprecated */
public function foo() : void {}
}
(new A())->foo();
```
### DeprecatedProperty
Emitted when getting/setting a deprecated property of a given class
```php
class A {
/**
* @deprecated
* @var ?string
*/
public $foo;
}
(new A())->foo = 5;
```
2018-08-10 19:25:25 +02:00
### DeprecatedTrait
Emitted when referring to a deprecated trait:
```php
/** @deprecated */
trait T {}
class A {
use T;
}
```
2018-02-07 00:44:53 +01:00
### DocblockTypeContradiction
2018-02-07 21:20:47 +01:00
Emitted when conditional doesn't make sense given the docblock types supplied.
2018-02-07 00:44:53 +01:00
```php
/**
* @param string $s
*
* @return void
*/
function foo($s) {
2018-02-07 21:20:47 +01:00
if ($s === 5) { }
2018-02-07 00:44:53 +01:00
}
```
2018-01-29 06:39:21 +01:00
### DuplicateArrayKey
Emitted when an array has a key more than once
```php
$arr = [
'a' => 1,
'b' => 2,
'c' => 3,
'c' => 4,
];
```
2017-12-12 06:49:40 +01:00
### DuplicateClass
Emitted when a class is defined twice
```php
class A {}
class A {}
```
2019-01-06 22:40:44 +01:00
### DuplicateFunction
Emitted when a function is defined twice
```php
function foo() : void {}
function bar() : void {}
function foo() : void {}
```
2019-01-02 17:18:22 +01:00
### DuplicateMethod
Emitted when a method is defined twice
```php
class A {
public function foo() {}
public function foo() {}
}
```
2017-12-12 06:49:40 +01:00
### DuplicateParam
2018-01-29 05:41:11 +01:00
Emitted when a function has a param defined twice
2017-12-12 06:49:40 +01:00
```php
2018-01-29 05:41:11 +01:00
function foo(int $b, string $b) {}
2017-12-12 06:49:40 +01:00
```
### EmptyArrayAccess
Emitted when attempting to access a value on an empty array
```php
$a = [];
$b = $a[0];
```
2018-01-07 23:17:18 +01:00
### FalsableReturnStatement
Emitted if a return statement contains a false value, but the function return type does not allow false
```php
function foo() : string {
if (rand(0, 1)) {
return "foo";
}
return false; // emitted here
}
```
2018-03-18 21:39:34 +01:00
### FalseOperand
2019-01-02 23:05:39 +01:00
Emitted when using `false` as part of an operation (e.g. `+` , `.` , `^` etc.)
2018-03-18 21:39:34 +01:00
```php
echo false . 'hello';
```
2017-12-12 06:49:40 +01:00
### ForbiddenCode
Emitted when Psalm encounters a var_dump, exec or similar expression that may make your code more vulnerable
```php
2018-04-07 21:16:46 +02:00
var_dump("bah");
2017-12-12 06:49:40 +01:00
```
2018-09-18 23:08:32 +02:00
### ForbiddenEcho
Emitted when Psalm encounters an echo statement and the `forbidEcho` flag in your config is set to `true`
```php
echo("bah");
```
2019-05-14 21:44:46 +02:00
### ImplementedParamTypeMismatch
Emitted when a class that inherits another, or implements an interface, has docblock param type that's entirely different to the parent. Subclasses of the parent return type are permitted, in docblocks.
```php
class D {
/** @param string $a */
public function foo($a): void {}
}
class E extends D {
/** @param int $a */
public function foo($a): void {}
}
```
2017-12-12 06:49:40 +01:00
### ImplementedReturnTypeMismatch
Emitted when a class that inherits another, or implements an interface, has docblock return type that's entirely different to the parent. Subclasses of the parent return type are permitted, in docblocks.
```php
class A {
/** @return bool */
public function foo() {
return true;
}
}
class B extends A {
/** @return string */
public function foo() {
2018-01-01 02:42:06 +01:00
return "hello";
2017-12-12 06:49:40 +01:00
}
}
```
### ImplicitToStringCast
2019-03-25 02:16:36 +01:00
Emitted when implicitly converting an object with a `__toString` method to a string
2017-12-12 06:49:40 +01:00
```php
class A {
public function __toString() {
return "foo";
}
}
function takesString(string $s) : void {}
takesString(new A);
```
### InaccessibleClassConstant
Emitted when a public/private class constant is not accessible from the calling context
```php
class A {
protected const FOO = 'FOO';
}
echo A::FOO;
```
### InaccessibleMethod
2017-12-12 07:16:51 +01:00
Emitted when attempting to access a protected/private method from outside its available scope
2017-12-12 06:49:40 +01:00
```php
2017-12-12 07:16:51 +01:00
class A {
protected function foo() : void {}
}
echo (new A)->foo();
2017-12-12 06:49:40 +01:00
```
2018-02-18 00:53:02 +01:00
### InterfaceInstantiation
2018-11-15 21:44:13 +01:00
Emitted when an attempt is made to instantiate an interface:
2018-02-18 00:53:02 +01:00
```php
interface I {}
new I();
```
2017-12-12 06:49:40 +01:00
### InaccessibleProperty
2017-12-12 07:16:51 +01:00
Emitted when attempting to access a protected/private property from outside its available scope
2017-12-12 06:49:40 +01:00
```php
2017-12-12 07:16:51 +01:00
class A {
/** @return string */
protected $foo;
}
echo (new A)->foo;
2017-12-12 06:49:40 +01:00
```
2018-12-02 00:37:49 +01:00
### InternalClass
2019-02-04 15:49:48 +01:00
Emitted when attempting to access a class marked as internal an unrelated namespace or class.
2018-12-02 00:37:49 +01:00
```php
namespace A {
/**
* @internal
*/
class Foo { }
}
namespace B {
class Bat {
public function batBat() {
$a = new \A\Foo();
}
}
}
```
### InternalMethod
2019-02-04 15:49:48 +01:00
Emitted when attempting to access a method marked as internal an unrelated namespace or class.
2018-12-02 00:37:49 +01:00
```php
namespace A {
class Foo {
/**
* @internal
*/
public static function barBar(): void {
}
}
}
namespace B {
class Bat {
public function batBat() {
\A\Foo::barBar();
}
}
}
```
### InternalProperty
2019-02-04 15:49:48 +01:00
Emitted when attempting to access a property marked as internal from an unrelated namespace or class.
2018-12-02 00:37:49 +01:00
```php
namespace A {
class Foo {
/**
* @internal
* @var ?int
*/
public $foo;
}
}
namespace B {
class Bat {
public function batBat() : void {
echo (new \A\Foo)->foo;
}
}
}
```
2017-12-12 06:49:40 +01:00
### InvalidArgument
2017-12-12 07:16:51 +01:00
Emitted when a supplied function/method argument is incompatible with the method signature or docblock one.
2017-12-12 06:49:40 +01:00
```php
2017-12-12 07:16:51 +01:00
class A {}
function foo(A $a) : void {}
foo("hello");
2017-12-12 06:49:40 +01:00
```
### InvalidArrayAccess
2017-12-12 07:16:51 +01:00
Emitted when attempting to access an array offset on a value that does not permit it
2017-12-12 06:49:40 +01:00
```php
2017-12-12 07:16:51 +01:00
$arr = 5;
echo $arr[0];
2017-12-12 06:49:40 +01:00
```
### InvalidArrayAssignment
2017-12-13 17:57:46 +01:00
Emitted when attempting to assign a value on a non-array
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$arr = 5;
$arr[0] = 3;
2017-12-12 06:49:40 +01:00
```
### InvalidArrayOffset
2019-02-04 15:49:48 +01:00
Emitted when attempting to access an array using a value that's not a valid offset for that array
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = [5, 20, 18];
echo $a["hello"];
2017-12-12 06:49:40 +01:00
```
### InvalidCast
2017-12-13 17:57:46 +01:00
Emitted when attempting to cast a value that's not castable
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
class A {}
$a = new A();
$b = (string)$a;
2017-12-12 06:49:40 +01:00
```
2018-01-01 02:32:47 +01:00
### InvalidCatch
Emitted when trying to catch a class/interface that doesn't extend `Exception` or implement `Throwable`
```php
class A {}
try {
$worked = true;
}
catch (A $e) {}
```
2017-12-12 06:49:40 +01:00
### InvalidClass
2017-12-13 17:57:46 +01:00
Emitted when referencing a class with the wrong casing
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
class Foo {}
(new foo());
2017-12-12 06:49:40 +01:00
```
2018-03-06 18:19:50 +01:00
### InvalidStringClass
Emitted when you have `allowStringToStandInForClass="false"` in your config and you’ re passing a string instead of calling a class directly
```php
class Foo {}
$a = "Foo";
new $a();
```
2017-12-12 06:49:40 +01:00
### InvalidClone
2017-12-13 17:57:46 +01:00
Emitted when trying to clone a value that's not cloneable
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = "hello";
$b = clone $a;
2017-12-12 06:49:40 +01:00
```
### InvalidDocblock
2017-12-13 17:57:46 +01:00
Emitted when there's an error in a docblock type
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
/** @var array() */
$a = [];
2017-12-12 06:49:40 +01:00
```
2019-02-23 17:31:33 +01:00
### InvalidDocblockParamName
Emitted when a docblock param name doesn’ t match up with a named param in the function.
```php
/**
* @param string[] $bar
*/
function foo(array $barb): void {
//
}
```
2018-01-07 23:17:18 +01:00
### InvalidFalsableReturnType
Emitted when a function can return a nullable value, but its given return type says otherwise
```php
function foo() : string {
if (rand(0, 1)) {
return "foo";
}
return false;
}
```
2017-12-12 06:49:40 +01:00
### InvalidFunctionCall
2017-12-13 17:57:46 +01:00
Emitted when calling a function on a non-callable variable
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = 5;
$b = $a();
2017-12-12 06:49:40 +01:00
```
### InvalidGlobal
2017-12-22 17:56:21 +01:00
Emitted when there's a reference to the global keyword where it's not expected
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
global $e;
2017-12-12 06:49:40 +01:00
```
### InvalidIterator
2017-12-13 17:57:46 +01:00
Emitted when trying to iterate over a value that's not iterable
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = 5;
foreach ($a as $b) {}
2017-12-12 06:49:40 +01:00
```
### InvalidMethodCall
2017-12-13 17:57:46 +01:00
Emitted when attempting to call a method on a non-object
2017-12-12 06:49:40 +01:00
```php
2017-12-13 17:57:46 +01:00
$a = 5;
$a->foo();
2017-12-12 06:49:40 +01:00
```
2018-01-07 23:17:18 +01:00
### InvalidNullableReturnType
Emitted when a function can return a nullable value, but its given return type says otherwise
```php
function foo() : string {
if (rand(0, 1)) {
return "foo";
}
return null;
}
```
2017-12-12 06:49:40 +01:00
### InvalidOperand
2018-11-15 21:44:13 +01:00
Emitted when using something as an operand that is unexpected
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {}
echo (new A) . ' ';
2017-12-12 06:49:40 +01:00
```
### InvalidParamDefault
2017-12-22 17:56:21 +01:00
Emitted when a function parameter default clashes with the type Psalm expects the param to be
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo(int $i = false) : void {}
2017-12-12 06:49:40 +01:00
```
### InvalidPassByReference
2017-12-22 17:56:21 +01:00
Emitted when passing a non-variable to a function that expects a by-ref variable
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo(array & $arr) : void {}
foo([0, 1, 2]);
2017-12-12 06:49:40 +01:00
```
### InvalidPropertyAssignment
2017-12-22 17:56:21 +01:00
Emitted when attempting to assign a property to a non-object
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
$a = "foo";
$a->bar = "bar";
2017-12-12 06:49:40 +01:00
```
2018-01-29 06:39:21 +01:00
### InvalidPropertyAssignmentValue
Emitted when attempting to assign a value to a property that cannot contain that type.
```php
class A {
/** @var string|null */
public $foo;
}
$a = new A();
$a->foo = new stdClass();
```
2017-12-12 06:49:40 +01:00
### InvalidPropertyFetch
2017-12-22 17:56:21 +01:00
Emitted when attempting to get a property from a non-object
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
$a = "foo";
echo $a->bar;
2017-12-12 06:49:40 +01:00
```
### InvalidReturnStatement
2017-12-22 17:56:21 +01:00
Emitted when a function return statement is incorrect
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo() : string {
return 5; // emitted here
}
2017-12-12 06:49:40 +01:00
```
### InvalidReturnType
2018-01-07 23:17:18 +01:00
Emitted when a function’ s signature return type is incorrect (often emitted with `InvalidReturnStatement` )
2017-12-12 06:49:40 +01:00
```php
2018-01-07 23:17:18 +01:00
function foo() : int {
2017-12-22 17:56:21 +01:00
if (rand(0, 1)) {
2018-01-07 23:17:18 +01:00
return "hello";
2017-12-22 17:56:21 +01:00
}
2018-01-07 23:17:18 +01:00
return 5;
2017-12-22 17:56:21 +01:00
}
2017-12-12 06:49:40 +01:00
```
### InvalidScalarArgument
2017-12-22 17:56:21 +01:00
Emitted when a scalar value is passed to a method that expected another scalar type
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo(int $i) : void {}
function bar(string $s) : void {
if (is_numeric($s)) {
foo($s);
}
}
2017-12-12 06:49:40 +01:00
```
### InvalidScope
2017-12-22 17:56:21 +01:00
Emitted when referring to `$this` outside a class
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
echo $this;
2017-12-12 06:49:40 +01:00
```
### InvalidStaticInvocation
2017-12-22 17:56:21 +01:00
Emitted when trying to call an instance function statically
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
/** @var ?string */
public $foo;
2017-12-12 06:49:40 +01:00
2017-12-22 17:56:21 +01:00
public function bar() : void {
echo $this->foo;
}
}
2017-12-12 06:49:40 +01:00
2017-12-22 17:56:21 +01:00
A::bar();
2017-12-12 06:49:40 +01:00
```
2019-01-25 21:31:17 +01:00
### InvalidTemplateParam
Emitted when using the `@extends` /`@implements` annotation to extend a class that has a template type constraint, where that extended value does not satisfy the parent class/interface's constraints.
```php
/**
* @template T as object
*/
class Base {}
/** @template -extends Base< int > */
class SpecializedByInheritance extends Base {}
```
2018-01-01 02:32:47 +01:00
### InvalidThrow
Emitted when trying to throw a class that doesn't extend `Exception` or implement `Throwable`
```php
class A {}
throw new A();
```
2017-12-12 06:49:40 +01:00
### InvalidToString
2017-12-22 17:56:21 +01:00
Emitted when a `__toString` method does not always return a `string`
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
public function __toString() {
return true;
}
}
2017-12-12 06:49:40 +01:00
```
2018-04-17 20:06:27 +02:00
### LessSpecificImplementedReturnType
Emitted when a class implements an interface method but its return type is less specific than the interface method return type
```php
class A {}
class B extends A {}
interface I {
/** @return B[] */
public function foo();
}
class D implements I {
/** @return A[] */
public function foo() {
return [new A, new A];
}
}
```
2017-12-12 06:49:40 +01:00
### LessSpecificReturnStatement
2017-12-22 17:56:21 +01:00
Emitted when a return statement is more general than the return type given for the function
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {}
class B extends A {}
2017-12-12 06:49:40 +01:00
2017-12-22 17:56:21 +01:00
function foo() : B {
return new A(); // emitted here
}
2017-12-12 06:49:40 +01:00
```
### LessSpecificReturnType
2017-12-22 17:56:21 +01:00
Emitted when a return type covers more possibilities than the function itself
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo() : ?int {
return 5;
}
```
### LoopInvalidation
2017-12-12 06:49:40 +01:00
2017-12-22 17:56:21 +01:00
Emitted when logic inside a loop invalidates one of the conditionals of the loop
```php
for ($i = 0; $i < 10 ; $ i + + ) {
$i = 5;
}
2017-12-12 06:49:40 +01:00
```
### MethodSignatureMismatch
2017-12-22 17:56:21 +01:00
Emitted when a method parameter differs from a parent method parameter, or if there are fewer parameters than the parent method
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
public function foo(int $i) : void {}
}
class B extends A {
public function foo(string $s) : void {}
}
2017-12-12 06:49:40 +01:00
```
2018-04-21 19:36:18 +02:00
### MethodSignatureMustOmitReturnType
2018-08-02 06:40:51 +02:00
Emitted when a `__clone` , `__construct` , or `__destruct` method is defined with a return type.
2018-04-21 19:36:18 +02:00
```php
class A {
public function __clone() : void {}
}
```
2018-01-07 23:17:18 +01:00
### MismatchingDocblockParamType
Emitted when an `@param` entry in a function’ s docblock doesn’ t match the param typehint,
```php
class A {}
class B {}
/**
* @param B $b // emitted here
*/
function foo(A $b) : void {}
```
This, however, is fine:
```php
class A {}
class B extends A {}
/**
* @param B
*/
function foo(A $b) : void {}
```
### MismatchingDocblockReturnType
Emitted when an `@return` entry in a function’ s docblock doesn’ t match the function return typehint
```php
class A {}
class B {}
/**
* @return B // emitted here
*/
function foo() : A {
return new A();
}
```
This, however, is fine:
```php
class A {}
class B extends A {}
/**
* @return B // emitted here
*/
function foo() : A {
return new B();
}
```
### MismatchingDocblockParamType
Emitted when an `@param` entry in a function’ s docblock doesn’ t match the param typehint
```php
/**
2018-02-07 00:44:53 +01:00
* @param int $b
2018-01-07 23:17:18 +01:00
*/
function foo(string $b) : void {}
```
2017-12-12 06:49:40 +01:00
### MisplacedRequiredParam
2017-12-22 17:56:21 +01:00
Emitted when a required param is before a param that is not required. Included in Psalm because it is an E_WARNING in PHP
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo(int $i = 5, string $j) : void {}
2017-12-12 06:49:40 +01:00
```
2018-01-29 05:41:11 +01:00
### MissingClosureParamType
2018-08-02 06:40:51 +02:00
Emitted when a closure parameter has no type information associated with it
2018-01-29 05:41:11 +01:00
```php
$a = function($a): string {
return "foo";
};
```
2017-12-12 06:49:40 +01:00
### MissingClosureReturnType
2017-12-22 17:56:21 +01:00
Emitted when a closure lacks a return type
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
$a = function() {
return "foo";
};
2017-12-12 06:49:40 +01:00
```
### MissingConstructor
2017-12-22 17:56:21 +01:00
Emitted when non-null properties without default values are defined in a class without a `__construct` method
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
/** @var string */
public $foo;
}
2017-12-12 06:49:40 +01:00
```
2018-02-17 17:36:20 +01:00
### MissingDependency
Emitted when referencing a class that doesn’ t exist
```php
/**
* @psalm -suppress UndefinedClass
*/
class A extends B {}
$a = new A();
```
2017-12-12 06:49:40 +01:00
### MissingDocblockType
2017-12-22 17:56:21 +01:00
Emitted when a docblock is present, but the type is missing or badly formatted
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
/** @var $a */
$a = [];
2017-12-12 06:49:40 +01:00
```
### MissingFile
2017-12-22 17:56:21 +01:00
Emitted when using `include` or `require` on a file that does not exist
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
require("nonexistent.php");
2017-12-12 06:49:40 +01:00
```
2018-01-29 05:41:11 +01:00
### MissingParamType
2018-08-02 06:40:51 +02:00
Emitted when a function parameter has no type information associated with it
2018-01-29 05:41:11 +01:00
```php
function foo($a) : void {}
```
2017-12-12 06:49:40 +01:00
### MissingPropertyType
2017-12-22 17:56:21 +01:00
Emitted when a property is defined on a class without a type
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
class A {
public $foo;
}
2017-12-12 06:49:40 +01:00
```
### MissingReturnType
2017-12-22 17:56:21 +01:00
Emitted when a function doesn't have a return type defined
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function foo() {
return "foo";
}
2017-12-12 06:49:40 +01:00
```
2019-01-24 23:55:03 +01:00
### MissingTemplateParam
Emitted when using the `@extends` /`@implements` annotation to extend a class without
extending all its template params.
```php
/**
* @template -implements IteratorAggregate< int >
*/
class SomeIterator implements IteratorAggregate
{
public function getIterator() {
yield 5;
}
}
```
2018-06-22 07:13:49 +02:00
### MissingThrowsDocblock
Emitted when a function doesn't have a return type defined
```php
function foo(int $x, int $y) : int {
if ($y === 0) {
throw new \InvalidArgumentException('Cannot divide by zero');
}
return intdiv($x, $y);
}
```
2017-12-12 06:49:40 +01:00
### MixedArgument
2017-12-22 17:56:21 +01:00
Emitted when Psalm cannot determine the type of an argument
2017-12-12 06:49:40 +01:00
```php
2017-12-22 17:56:21 +01:00
function takesInt(int $i) : void {}
2017-12-24 01:11:08 +01:00
takesInt($_GET['foo']);
2017-12-12 06:49:40 +01:00
```
2019-04-26 00:02:19 +02:00
### MixedArgumentTypeCoercion
Emitted when Psalm cannot be sure that part of an array/iterabble argument's type constraints can be fulfilled
```php
function foo(array $a) : void {
takesStringArray($a);
}
/** @param string[] $a */
function takesStringArray(array $a) : void {}
```
2017-12-12 06:49:40 +01:00
### MixedArrayAccess
2017-12-22 17:56:21 +01:00
Emitted when trying to access an array offset on a value whose type Psalm cannot determine
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
echo $_GET['foo'][0];
2017-12-12 06:49:40 +01:00
```
### MixedArrayAssignment
2017-12-22 17:56:21 +01:00
Emitted when trying to assign a value to an array offset on a value whose type Psalm cannot determine
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
$_GET['foo'][0] = "5";
2017-12-12 06:49:40 +01:00
```
### MixedArrayOffset
2017-12-22 17:56:21 +01:00
Emitted when attempting to access an array offset where Psalm cannot determine the offset type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
echo [1, 2, 3][$_GET['foo']];
2017-12-12 06:49:40 +01:00
```
2019-04-26 00:02:19 +02:00
### MixedArrayTypeCoercion
Emitted when trying to access an array with a less specific offset than is expected
```php
/**
* @param array< array-key , int > $a
* @param array< int , string > $b
*/
function foo(array $a, array $b) : void {
foreach ($a as $j => $k) {
echo $b[$j];
}
}
```
2017-12-12 06:49:40 +01:00
### MixedAssignment
2017-12-31 19:13:12 +01:00
Emitted when assigning a variable to a value for which Psalm cannot infer a type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
$a = $_GET['foo'];
2017-12-12 06:49:40 +01:00
```
2019-02-10 22:15:52 +01:00
### MixedFunctionCall
Emitted when calling a function on a value whose type Psalm cannot infer.
```php
/** @psalm -suppress MixedAssignment */
$a = $_GET['foo'];
$a();
```
2017-12-12 06:49:40 +01:00
### MixedInferredReturnType
2017-12-24 01:11:08 +01:00
Emitted when Psalm cannot determine a function's return type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
function foo() : int {
return $_GET['foo'];
}
2017-12-12 06:49:40 +01:00
```
### MixedMethodCall
2017-12-24 01:11:08 +01:00
Emitted when calling a method on a value that Psalm cannot infer a type for
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
/** @param mixed $a */
function foo($a) : void {
$a->foo();
}
2017-12-12 06:49:40 +01:00
```
### MixedOperand
2017-12-24 01:11:08 +01:00
Emitted when Psalm cannot infer a type for an operand in any calculated expression
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
echo $_GET['foo'] + "hello";
2017-12-12 06:49:40 +01:00
```
### MixedPropertyAssignment
2017-12-31 19:13:12 +01:00
Emitted when assigning a property to a value for which Psalm cannot infer a type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
/** @param mixed $a */
function foo($a) : void {
$a->foo = "bar";
}
2017-12-12 06:49:40 +01:00
```
### MixedPropertyFetch
2017-12-31 19:13:12 +01:00
Emitted when retrieving a property on a value for which Psalm cannot infer a type
2017-12-12 06:49:40 +01:00
```php
2017-12-24 01:11:08 +01:00
/** @param mixed $a */
function foo($a) : void {
echo $a->foo;
}
2017-12-12 06:49:40 +01:00
```
2019-04-26 00:02:19 +02:00
### MixedPropertyTypeCoercion
Emitted when Psalm cannot be sure that part of an array/iterabble argument's type constraints can be fulfilled
```php
class A {
/** @var string[] */
public $takesStringArray = [];
}
function foo(A $a, array $arr) : void {
$a->takesStringArray = $arr;
}
```
2018-01-07 23:17:18 +01:00
### MixedReturnStatement
Emitted when Psalm cannot determine the type of a given return statement
```php
function foo() : int {
return $_GET['foo']; // emitted here
}
```
2019-04-26 00:02:19 +02:00
### MixedReturnTypeCoercion
2017-12-12 06:49:40 +01:00
2019-04-26 00:02:19 +02:00
Emitted when Psalm cannot be sure that part of an array/iterabble return type's constraints can be fulfilled
2017-12-12 06:49:40 +01:00
```php
2019-04-26 00:02:19 +02:00
/**
* @return string[]
*/
function foo(array $a) : array {
return $a;
}
2017-12-12 06:49:40 +01:00
```
2019-04-26 00:02:19 +02:00
### MixedStringOffsetAssignment
2017-12-12 06:49:40 +01:00
2019-04-26 00:02:19 +02:00
Emitted when assigning a value on a string using a value for which Psalm cannot infer a type
2017-12-12 06:49:40 +01:00
```php
2019-04-26 00:02:19 +02:00
"hello"[0] = $_GET['foo'];
2017-12-12 06:49:40 +01:00
```
2018-01-29 06:39:21 +01:00
### MoreSpecificImplementedParamType
Emitted when a class implements an interface method but a param type is less specific than the interface method param type
```php
class A {}
class B extends A {
public function bar(): void {}
}
class C extends A {
public function bar(): void {}
}
class D {
public function foo(A $a): void {}
}
class E extends D {
/** @param B|C $a */
public function foo(A $a): void {
$a->bar();
}
}
```
2017-12-12 06:49:40 +01:00
### MoreSpecificReturnType
2017-12-31 19:13:12 +01:00
Emitted when the declared return type for a method is more specific than the inferred one (emitted in the same methods that `LessSpecificReturnStatement` is)
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
class A {}
class B extends A {}
function foo() : B {
/** @psalm -suppress LessSpecificReturnStatement */
return new A();
}
2017-12-12 06:49:40 +01:00
```
2019-01-02 23:05:39 +01:00
### NoValue
Emitted when using the result of a function that never returns.
```php
/**
* @return never-returns
*/
function foo() : void {
exit();
}
$a = foo();
```
2017-12-12 06:49:40 +01:00
### NoInterfaceProperties
2017-12-31 19:13:12 +01:00
Emitted when trying to fetch a property on an interface as interfaces, by definition, do not have definitions for properties.
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
interface I {}
class A implements I {
/** @var ?string */
public $foo;
}
function bar(I $i) : void {
if ($i->foo) {}
}
2017-12-12 06:49:40 +01:00
```
### NonStaticSelfCall
2018-01-29 05:41:11 +01:00
Emitted when calling a non-static function statically
2017-12-12 06:49:40 +01:00
```php
2018-01-29 05:41:11 +01:00
class A {
public function foo(): void {}
2017-12-12 06:49:40 +01:00
2018-06-04 01:11:07 +02:00
public static function bar(): void {
2018-01-29 05:41:11 +01:00
self::foo();
}
}
2017-12-12 06:49:40 +01:00
```
2018-01-07 23:17:18 +01:00
### NullableReturnStatement
Emitted if a return statement contains a null value, but the function return type is not nullable
```php
function foo() : string {
if (rand(0, 1)) {
return "foo";
}
return null; // emitted here
}
```
2017-12-12 06:49:40 +01:00
### NullArgument
2017-12-31 19:13:12 +01:00
Emitted when calling a function with a null value argument when the function does not expect it
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
function foo(string $s) : void {}
foo(null);
2017-12-12 06:49:40 +01:00
```
### NullArrayAccess
2017-12-31 19:13:12 +01:00
Emitted when trying to access an array value on `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$arr = null;
echo $arr[0];
2017-12-12 06:49:40 +01:00
```
### NullArrayOffset
2017-12-31 19:13:12 +01:00
Emitted when trying to access an array offset with `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$arr = ['' => 5, 'foo' => 1];
echo $arr[null];
2017-12-12 06:49:40 +01:00
```
### NullFunctionCall
2017-12-31 19:13:12 +01:00
Emitted when trying to use `null` as a `callable`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$arr = null;
echo $arr();
2017-12-12 06:49:40 +01:00
```
### NullIterator
2017-12-31 19:13:12 +01:00
Emitted when iterating over `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
foreach (null as $a) {}
2017-12-12 06:49:40 +01:00
```
### NullOperand
2019-01-02 23:05:39 +01:00
Emitted when using `null` as part of an operation (e.g. `+` , `.` , `^` etc.)
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
echo null . 'hello';
2017-12-12 06:49:40 +01:00
```
### NullPropertyAssignment
2017-12-31 19:13:12 +01:00
Emitted when trying to set a property on `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$a = null;
$a->foo = "bar";
2017-12-12 06:49:40 +01:00
```
### NullPropertyFetch
2017-12-31 19:13:12 +01:00
Emitted when trying to fetch a property on a `null` value
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$a = null;
echo $a->foo;
2017-12-12 06:49:40 +01:00
```
### NullReference
2017-12-31 19:13:12 +01:00
Emitted when attempting to call a method on `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
$a = null;
$a->foo();
2017-12-12 06:49:40 +01:00
```
### OverriddenMethodAccess
2017-12-31 19:13:12 +01:00
Emitted when a method is less accessible than its parent
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
class A {
public function foo() : void {}
}
class B extends A {
protected function foo() : void {}
}
2017-12-12 06:49:40 +01:00
```
2018-03-04 18:24:50 +01:00
### OverriddenPropertyAccess
Emitted when a property is less accessible than the same-named property in its parent class
```php
class A {
/** @var string|null */
public $foo;
}
class B extends A {
/** @var string|null */
protected $foo;
}
```
2017-12-12 06:49:40 +01:00
### ParadoxicalCondition
2017-12-31 19:13:12 +01:00
Emitted when a paradox is encountered in your programs logic that could not be caught by `RedundantCondition`
2017-12-12 06:49:40 +01:00
```php
2018-05-08 22:34:08 +02:00
function foo($a) : void {
if ($a) return;
2017-12-31 19:13:12 +01:00
if ($a) echo "cannot happen";
}
2017-12-12 06:49:40 +01:00
```
### ParentNotFound
2017-12-31 20:45:23 +01:00
Emitted when using `parent::` in a class without a parent class.
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
public function foo() : void {
parent::foo();
}
}
2017-12-12 06:49:40 +01:00
```
2018-09-29 06:15:39 +02:00
### ParseError
Emitted when the PHP Parser encounters an error.
```php
class A {
public function foo() : void {
echo "foo"
}
}
```
2019-01-07 14:38:56 +01:00
### PluginIssue
Can be emitted by plugins.
2017-12-12 06:49:40 +01:00
### PossiblyFalseArgument
2017-12-31 20:45:23 +01:00
Emitted when a function argument is possibly `false` , but the function doesn’ t expect `false` . This is distinct from a function argument is possibly `bool` , which results in `PossiblyInvalidArgument` .
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
function foo(string $s) : void {
$a_pos = strpos($s, "a");
echo substr($s, $a_pos);
}
2017-12-12 06:49:40 +01:00
```
2018-03-21 03:59:22 +01:00
### PossiblyFalseIterator
Emitted when trying to iterate over a value that may be `false`
```php
$arr = rand(0, 1) ? [1, 2, 3] : false;
foreach ($arr as $a) {}
```
2018-03-18 21:39:34 +01:00
### PossiblyFalseOperand
2019-04-26 00:02:19 +02:00
Emitted when using a possibly `false` value as part of an operation (e.g. `+` , `.` , `^` etc).
2018-03-18 21:39:34 +01:00
```php
function foo(string $a) : void {
echo strpos($a, ":") + 5;
}
```
2018-01-29 06:39:21 +01:00
### PossiblyFalsePropertyAssignmentValue
Emitted when trying to assign a value that may be false to a property that only takes non-false values.
```php
class A {
/** @var int */
public $foo = 0;
}
function assignToA(string $s) {
$a = new A();
$a->foo = strpos("haystack", $s);
}
```
2017-12-12 06:49:40 +01:00
### PossiblyFalseReference
2017-12-31 20:45:23 +01:00
Emitted when making a method call on a value than might be `false`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
public function bar() : void {}
}
2017-12-12 06:49:40 +01:00
2017-12-31 20:45:23 +01:00
/** @return A|false */
function foo() {
return rand(0, 1) ? new A : false;
}
foo()->bar();
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidArgument
Emitted when
```php
2018-01-29 05:41:11 +01:00
/** @return int|stdClass */
2017-12-31 20:45:23 +01:00
function foo() {
2018-01-29 05:41:11 +01:00
return rand(0, 1) ? 5 : new stdClass;
2017-12-31 20:45:23 +01:00
}
function bar(int $i) : void {}
bar(foo());
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidArrayAccess
2017-12-31 20:45:23 +01:00
Emitted when attempting to access an array offset on a value that may not be an array
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
$arr = rand(0, 1) ? 5 : [4, 3, 2, 1];
echo $arr[0];
2017-12-12 06:49:40 +01:00
```
### PossiblyInvalidArrayAssignment
2017-12-31 20:45:23 +01:00
Emitted when attempting to assign an array offset on a value that may not be an array
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
$arr = rand(0, 1) ? 5 : [4, 3, 2, 1];
$arr[0] = "hello";
2017-12-12 06:49:40 +01:00
```
2019-03-17 22:10:51 +01:00
### PossiblyInvalidCast
Emitted when attempting to cast a value that may not be castable
```php
class A {}
class B {
public function __toString() {
return 'hello';
}
}
$c = (string) (rand(0, 1) ? new A() : new B());
```
2017-12-12 06:49:40 +01:00
### PossiblyInvalidArrayOffset
2017-12-31 20:45:23 +01:00
Emitted when it’ s possible that the array offset is not applicable to the value you’ re trying to access.
2017-12-12 06:49:40 +01:00
```php
2018-01-01 18:00:02 +01:00
$arr = rand(0, 1) ? ["a" => 5] : "hello";
2017-12-31 20:45:23 +01:00
echo $arr[0];
2017-12-12 06:49:40 +01:00
```
2018-01-01 18:00:02 +01:00
### PossiblyInvalidFunctionCall
Emitted when trying to call a function on a value that may not be callable
```php
$a = rand(0, 1) ? 5 : function() : int { return 5; };
$b = $a();
```
2018-03-21 03:59:22 +01:00
### PossiblyInvalidIterator
Emitted when trying to iterate over a value that may be invalid
```php
$arr = rand(0, 1) ? [1, 2, 3] : "hello";
foreach ($arr as $a) {}
```
2017-12-12 06:49:40 +01:00
### PossiblyInvalidMethodCall
2017-12-31 20:45:23 +01:00
Emitted when trying to call a method on a value that may not be an object
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
public function bar() : void {}
}
2017-12-12 06:49:40 +01:00
2017-12-31 20:45:23 +01:00
/** @return A|int */
function foo() {
return rand(0, 1) ? new A : 5;
}
foo()->bar();
2017-12-12 06:49:40 +01:00
```
2018-03-18 21:39:34 +01:00
### PossiblyInvalidOperand
2019-04-26 00:02:19 +02:00
Emitted when using a possibly invalid value as part of an operation (e.g. `+` , `.` , `^` etc.
2018-03-18 21:39:34 +01:00
```php
function foo() : void {
$b = rand(0, 1) ? [] : 4;
echo $b + 5;
}
```
2017-12-12 06:49:40 +01:00
### PossiblyInvalidPropertyAssignment
2017-12-31 20:45:23 +01:00
Emitted when trying to assign a property on a value that may not be an object or may be an object that doesn’ t have the desired property.
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
/** @var ?string */
public $bar;
}
2017-12-12 06:49:40 +01:00
2017-12-31 20:45:23 +01:00
/** @return A|int */
function foo() {
return rand(0, 1) ? new A : 5;
}
$a = foo();
$a->bar = "5";
2017-12-12 06:49:40 +01:00
```
2018-01-29 06:39:21 +01:00
### PossiblyInvalidPropertyAssignmentValue
Emitted when trying to assign a possibly invalid value to a typed property.
```php
class A {
/** @var int[] */
public $bb = [];
}
class B {
/** @var string[] */
public $bb;
}
$c = rand(0, 1) ? new A : new B;
$c->bb = ["hello", "world"];
```
2017-12-12 06:49:40 +01:00
### PossiblyInvalidPropertyFetch
2017-12-31 20:45:23 +01:00
Emitted when trying to fetch a property on a value that may not be an object or may be an object that doesn’ t have the desired property.
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
/** @var ?string */
public $bar;
}
/** @return A|int */
function foo() {
return rand(0, 1) ? new A : 5;
}
2017-12-12 06:49:40 +01:00
2017-12-31 20:45:23 +01:00
$a = foo();
echo $a->bar;
2017-12-12 06:49:40 +01:00
```
### PossiblyNullArgument
2017-12-31 20:45:23 +01:00
Emitted when calling a function with a value that’ s possibly null when the function does not expect it
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
function foo(string $s) : void {}
foo(rand(0, 1) ? "hello" : null);
2017-12-12 06:49:40 +01:00
```
### PossiblyNullArrayAccess
2017-12-31 20:45:23 +01:00
Emitted when trying to access an array offset on a possibly null value
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?array $a) : void {
2017-12-31 20:45:23 +01:00
echo $a[0];
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullArrayAssignment
2017-12-31 20:45:23 +01:00
Emitted when trying to set a value on a possibly null array
2017-12-12 06:49:40 +01:00
```php
2018-01-29 05:41:11 +01:00
$a = null;
$a[0][] = 1;
2017-12-12 06:49:40 +01:00
```
### PossiblyNullArrayOffset
2017-12-31 20:45:23 +01:00
Emitted when trying to access a value on an array using a possibly null offset
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?int $a) : void {
2017-12-31 20:45:23 +01:00
echo [1, 2, 3, 4][$a];
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullFunctionCall
2017-12-31 20:45:23 +01:00
Emitted when trying to call a function on a value that may be null
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?callable $a) : void {
2017-12-31 20:45:23 +01:00
$a();
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullIterator
2017-12-31 20:45:23 +01:00
Emitted when trying to iterate over a value that may be null
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?array $arr) : void {
2017-12-31 20:45:23 +01:00
foreach ($arr as $a) {}
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullOperand
2019-03-29 19:09:06 +01:00
Emitted when using a possibly `null` value as part of an operation (e.g. `+` , `.` , `^` etc.)
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:40:27 +01:00
function foo(?int $a) : void {
2017-12-31 20:45:23 +01:00
echo $a + 5;
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullPropertyAssignment
2017-12-31 20:45:23 +01:00
Emitted when trying to assign a property to a possibly null object
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
/** @var ?string */
public $foo;
}
function foo(?A $a) : void {
$a->foo = "bar";
}
2017-12-12 06:49:40 +01:00
```
2018-01-29 06:39:21 +01:00
### PossiblyNullPropertyAssignmentValue
Emitted when trying to assign a value that may be null to a property that only takes non-null values.
```php
class A {
/** @var string */
public $foo = "bar";
}
function assignToA(?string $s) {
$a = new A();
$a->foo = $s;
}
```
2017-12-12 06:49:40 +01:00
### PossiblyNullPropertyFetch
2017-12-31 20:45:23 +01:00
Emitted when trying to fetch a property on a possibly null object
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
/** @var ?string */
public $foo;
}
function foo(?A $a) : void {
echo $a->foo;
}
2017-12-12 06:49:40 +01:00
```
### PossiblyNullReference
2017-12-31 20:45:23 +01:00
Emitted when trying to call a method on a possibly null value
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
public function bar() : void {}
}
function foo(?A $a) : void {
$a->bar();
}
2017-12-12 06:49:40 +01:00
```
2018-04-17 20:06:27 +02:00
### PossiblyUndefinedArrayOffset
Emitted when trying to access a possibly undefined array offset
```php
if (rand(0, 1)) {
$arr = ["a" => 1, "b" => 2];
} else {
$arr = ["a" => 3];
}
echo $arr["b"];
```
2017-12-12 06:49:40 +01:00
### PossiblyUndefinedGlobalVariable
2017-12-31 20:45:23 +01:00
Emitted when trying to access a variable in the global scope that may not be defined
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
if (rand(0, 1)) {
$a = 5;
}
echo $a;
2017-12-12 06:49:40 +01:00
```
### PossiblyUndefinedMethod
2017-12-31 20:45:23 +01:00
Emitted when trying to access a method that may not be defined on the object
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
public function bar() : void {}
}
class B {}
2017-12-12 06:49:40 +01:00
2017-12-31 20:45:23 +01:00
$a = rand(0, 1) ? new A : new B;
$a->bar();
2017-12-12 06:49:40 +01:00
```
### PossiblyUndefinedVariable
2017-12-31 20:45:23 +01:00
Emitted when trying to access a variable in function scope that may not be defined
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
function foo() : void {
if (rand(0, 1)) {
$a = 5;
}
echo $a;
}
2017-12-12 06:49:40 +01:00
```
### PossiblyUnusedMethod
2017-12-31 20:45:23 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any calls to a given class method
2017-12-12 06:49:40 +01:00
```php
2017-12-31 20:45:23 +01:00
class A {
public function foo() : void {}
public function bar() : void {}
}
(new A)->foo();
2017-12-12 06:49:40 +01:00
```
2018-01-01 02:32:47 +01:00
### PossiblyUnusedParam
2017-12-12 06:49:40 +01:00
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a particular parameter in a public/protected method
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
public function foo(int $a, int $b) : int {
return $a + 4;
}
2017-12-31 20:45:23 +01:00
}
2018-01-29 05:41:11 +01:00
$a = new A();
$a->foo(1, 2);
2017-12-12 06:49:40 +01:00
```
2018-01-29 06:39:21 +01:00
### PossiblyUnusedProperty
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a particular public/protected property
```php
class A {
/** @var string|null */
public $foo;
/** @var int|null */
public $bar;
}
$a = new A();
echo $a->foo;
```
2017-12-12 06:49:40 +01:00
### PropertyNotSetInConstructor
2017-12-31 23:32:35 +01:00
Emitted when a non-null property without a default value is declared but not set in the class’ s constructor
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
class A {
/** @var string */
public $foo;
2017-12-12 06:49:40 +01:00
2017-12-31 23:32:35 +01:00
public function __construct() {}
}
2017-12-12 06:49:40 +01:00
```
2019-04-26 00:02:19 +02:00
### PropertyTypeCoercion
Emitted when setting a property with an value which has a less specific type than the property expects
```php
class A {}
class B extends A {}
function takesA(C $c, A $a) : void {
$c->b = $a;
}
class C {
/** @var ?B */
public $b;
}
```
2017-12-12 06:49:40 +01:00
### RawObjectIteration
2017-12-31 23:32:35 +01:00
Emitted when iterating over an object’ s properties. This issue exists because it may be undesired behaviour (e.g. you may have meant to iterate over an array)
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
class A {
2018-01-29 05:41:11 +01:00
/** @var string|null */
2017-12-31 23:32:35 +01:00
public $foo;
2018-01-29 05:41:11 +01:00
/** @var string|null */
2017-12-31 23:32:35 +01:00
public $bar;
}
2017-12-12 06:49:40 +01:00
2017-12-31 23:32:35 +01:00
function takesA(A $a) {
foreach ($a as $property) {}
}
2017-12-12 06:49:40 +01:00
```
### RedundantCondition
2017-12-31 19:13:12 +01:00
Emitted when conditional is redundant given previous assertions
2017-12-12 06:49:40 +01:00
```php
2017-12-31 19:13:12 +01:00
class A {}
2018-04-10 07:27:26 +02:00
function foo(A $a) : ?A {
2017-12-31 19:13:12 +01:00
if ($a) return $a;
2018-04-10 07:27:26 +02:00
return null;
2017-12-31 19:13:12 +01:00
}
2017-12-12 06:49:40 +01:00
```
2018-02-07 21:20:47 +01:00
### RedundantConditionGivenDocblockType
Emitted when conditional is redundant given information supplied in one or more docblocks.
This may be desired (e.g. when checking user input) so is distinct from RedundantCondition, which only applies to non-docblock types.
```php
/**
* @param string $s
*
* @return void
*/
function foo($s) {
if (is_string($s)) {};
}
```
2017-12-12 06:49:40 +01:00
### ReferenceConstraintViolation
2017-12-31 23:32:35 +01:00
Emitted when changing the type of a pass-by-reference variable
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
function foo(string & $a) {
$a = 5;
}
2017-12-12 06:49:40 +01:00
```
### ReservedWord
2017-12-31 23:32:35 +01:00
Emitted when using a reserved word as a class name
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
function foo(resource $res) : void {}
2017-12-12 06:49:40 +01:00
```
2019-03-29 19:09:06 +01:00
### TraitMethodSignatureMismatch
Emitted when a method's signature or return type differs from corresponding trait-defined method
```php
trait T {
abstract public function foo(int $i);
}
class A {
use T;
public function foo(string $s) : void {}
}
```
2017-12-12 06:49:40 +01:00
### TooFewArguments
2017-12-31 23:32:35 +01:00
Emitted when calling a function with fewer arguments than the function has parameters
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
function foo(string $a) : void {}
foo();
2017-12-12 06:49:40 +01:00
```
### TooManyArguments
2017-12-31 23:32:35 +01:00
Emitted when calling a function with more arguments than the function has parameters
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
function foo(string $a) : void {}
foo("hello", 4);
2017-12-12 06:49:40 +01:00
```
2019-01-25 21:31:17 +01:00
### TooManyTemplateParams
Emitted when using the `@extends` /`@implements` annotation to extend a class and adds too
many types.
```php
/**
* @template -implements IteratorAggregate< int , string , int >
*/
class SomeIterator implements IteratorAggregate
{
public function getIterator() {
yield 5;
}
}
```
2017-12-12 06:49:40 +01:00
### TypeDoesNotContainNull
2017-12-31 23:32:35 +01:00
Emitted when checking a non-nullable type for `null`
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
$a = "hello";
if ($a === null) {}
2017-12-12 06:49:40 +01:00
```
### TypeDoesNotContainType
2017-12-31 23:32:35 +01:00
Emitted checking whether one value has a type or value that is impossible given its currently-known type
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
$a = "hello";
if ($a === 5) {}
2017-12-12 06:49:40 +01:00
```
2019-03-24 21:17:14 +01:00
### UncaughtThrowInGlobalScope
Emitted when a possible exception isn't caught in global scope
```php
/**
* @throws \Exception
*/
function foo() : int {
return random_int(0, 1);
}
foo();
```
2017-12-12 06:49:40 +01:00
### UndefinedClass
2017-12-31 23:32:35 +01:00
Emitted when referencing a class that doesn’ t exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
$a = new A();
2017-12-12 06:49:40 +01:00
```
### UndefinedConstant
2017-12-31 23:32:35 +01:00
Emitted when referencing a constant that doesn’ t exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
echo FOO_BAR;
2017-12-12 06:49:40 +01:00
```
### UndefinedFunction
2017-12-31 23:32:35 +01:00
Emitted when referencing a function that doesn't exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
foo();
2017-12-12 06:49:40 +01:00
```
### UndefinedGlobalVariable
2017-12-31 23:32:35 +01:00
Emitted when referencing a variable that doesn't exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
echo $a;
2017-12-12 06:49:40 +01:00
```
2019-03-07 17:16:40 +01:00
### UndefinedInterface
Emitted when referencing an interface that doesn’ t exist but does have an identically-named class.
```php
class C {}
interface I extends C {}
```
2017-12-12 06:49:40 +01:00
### UndefinedMethod
2017-12-31 23:32:35 +01:00
Emitted when calling a method that doesn’ t exist
2017-12-12 06:49:40 +01:00
```php
2017-12-31 23:32:35 +01:00
class A {}
A::foo();
2017-12-12 06:49:40 +01:00
```
2019-01-13 19:07:53 +01:00
### UndefinedInterfaceMethod
Emitted when calling a method that doesn’ t exist on an interface
```php
interface I {}
function foo(I $i) {
$i->bar();
}
```
2017-12-12 06:49:40 +01:00
### UndefinedPropertyAssignment
2018-01-01 02:32:47 +01:00
Emitted when assigning a property on an object that doesn’ t have that property defined
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {}
$a = new A();
$a->foo = "bar";
2017-12-12 06:49:40 +01:00
```
### UndefinedPropertyFetch
2018-01-01 02:32:47 +01:00
Emitted when getting a property on an object that doesn’ t have that property defined
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {}
$a = new A();
echo $a->foo;
2017-12-12 06:49:40 +01:00
```
### UndefinedThisPropertyAssignment
2018-01-01 02:32:47 +01:00
Emitted when assigning a property on an object in one of that object’ s methods when no such property exists
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
function foo() {
$this->foo = "bar";
}
}
2017-12-12 06:49:40 +01:00
```
### UndefinedThisPropertyFetch
2018-01-01 02:32:47 +01:00
Emitted when getting a property for an object in one of that object’ s methods when no such property exists
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
function foo() {
echo $this->foo;
}
}
2017-12-12 06:49:40 +01:00
```
### UndefinedTrait
2018-01-01 02:32:47 +01:00
Emitted when referencing a trait that doesn’ t exist
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
use T;
}
2017-12-12 06:49:40 +01:00
```
### UndefinedVariable
2018-01-01 02:32:47 +01:00
Emitted when referencing a variable that doesn't exist in a given function’ s scope
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
function foo() {
echo $a;
}
2017-12-12 06:49:40 +01:00
```
### UnevaluatedCode
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm encounters code that will not be evaluated
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
function foo() : void {
return;
$a = "foo";
}
2017-12-12 06:49:40 +01:00
```
### UnimplementedAbstractMethod
2018-01-01 02:32:47 +01:00
Emitted when a class extends another, but does not implement all of its abstract methods
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
abstract class A {
abstract public function foo();
}
class B extends A {}
2017-12-12 06:49:40 +01:00
```
### UnimplementedInterfaceMethod
2018-01-01 02:32:47 +01:00
Emitted when a class `implements` an interface but does not implement all of its methods
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
interface I {
public function foo();
}
class A implements I {}
2017-12-12 06:49:40 +01:00
```
2019-02-13 19:32:19 +01:00
### UninitializedProperty
Emitted when a property is used in a constructor before it is initialized
```php
class A {
/** @var string */
public $foo;
public function __construct() {
echo strlen($this->foo);
$this->foo = "foo";
}
}
```
2017-12-12 06:49:40 +01:00
### UnrecognizedExpression
2018-01-01 02:32:47 +01:00
Emitted when Psalm encounters an expression that it doesn't know how to handle. This should never happen.
2017-12-12 06:49:40 +01:00
### UnrecognizedStatement
2018-01-01 02:32:47 +01:00
Emitted when Psalm encounters a code construct that it doesn't know how to handle. This should never happen.
2017-12-12 06:49:40 +01:00
### UnresolvableInclude
2018-01-01 02:32:47 +01:00
Emitted when Psalm cannot figure out what specific file is being included/required by PHP.
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
function requireFile(string $s) : void {
require_once($s);
}
2017-12-12 06:49:40 +01:00
```
### UnusedClass
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a given class
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {}
class B {}
$a = new A();
2017-12-12 06:49:40 +01:00
```
### UnusedMethod
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a given private method or function
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
class A {
public function __construct() {
$this->foo();
}
private function foo() : void {}
private function bar() : void {}
}
2018-01-29 05:41:11 +01:00
$a = new A();
2018-01-01 02:32:47 +01:00
```
2019-03-05 21:45:09 +01:00
### UnusedClosureParam
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a particular parameter in a closure.
```php
$a = function (int $a, int $b) : int {
return $a + 4;
};
/**
* @param callable(int,int):int $c
*/
function foo(callable $c) : int {
return $c(2, 4);
}
```
2018-01-01 02:32:47 +01:00
### UnusedParam
2017-12-12 06:49:40 +01:00
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a particular parameter in a private method or function
```php
function foo(int $a, int $b) : int {
return $a + 4;
}
2017-12-12 06:49:40 +01:00
```
2018-01-29 06:39:21 +01:00
### UnusedProperty
Emitted when `--find-dead-code` is turned on and Psalm cannot find any uses of a private property
```php
class A {
/** @var string|null */
private $foo;
/** @var int|null */
private $bar;
public function getFoo(): ?string {
return $this->foo;
}
}
$a = new A();
echo $a->getFoo();
```
2017-12-12 06:49:40 +01:00
### UnusedVariable
2018-01-01 02:32:47 +01:00
Emitted when `--find-dead-code` is turned on and Psalm cannot find any references to a variable, once instantiated
2017-12-12 06:49:40 +01:00
```php
2018-01-01 02:32:47 +01:00
function foo() : void {
$a = 5;
$b = 4;
echo $b;
}
2017-12-12 06:49:40 +01:00
```