rspec/rules/S2014/rule.adoc
2020-06-30 17:16:12 +02:00

33 lines
625 B
Plaintext

<code>$this</code> refers to the current class instance. But static methods can be accessed without instantiating the class, and <code>$this</code> is not available to them. Using <code>$this</code> in a static context will result in a fatal error at runtime.
== Noncompliant Code Example
----
class Clazz {
$name=NULL; // instance variable
public static function foo(){
if ($this->name != NULL) {
// ...
}
}
}
----
== Compliant Solution
----
class Clazz {
$name=NULL; // instance variable
public static function foo($nameParam){
if ($nameParam != NULL) {
// ...
}
}
}
----