You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- apache#6703
- Show errors when `$this` is used in static context(static methods, static closures, static arrow functions)
- Add unit tests
Note:
Check only $this in TypeDeclarations because Frameworks may use `$this` in the global scope.
e.g. CakePHP framework can use `$this`(e.g. `$this->Html->link()`) in the global scope of view files.
(see: https://book.cakephp.org/5/en/views.html)
Example:
```php
class Example {
private int $field = 1;
public static function staticMethod(): void {
$this->field; // error
}
public function method(): void {
$staticClosure = static function() {
var_dump($this); // error
};
$staticArrow = static fn() => $this; // error
echo $this->field;
}
}
```
Description
I may mistakenly use $this in a static method. It is expected that NetBeans will show this error in the code before that I run it in the PHP engine.
Use case/motivation
for example in the following code, there are a Fatal error.
but Netbeans do not find it.
Related issues
No response
Are you willing to submit a pull request?
No
The text was updated successfully, but these errors were encountered: