Skip to content

MIR0001

InvalidScope

$this is used in a context where it is not available: either outside any class, or inside a static method where no object instance exists.

<?php
class Counter {
private int $count = 0;
public static function reset(): void {
$this->count = 0; // $this is not available in a static method
}
}

Remove the use of $this, change the method to non-static, or use a static property instead.

<?php
class Counter {
private static int $count = 0;
public static function reset(): void {
self::$count = 0;
}
}