rspec/rules/S2014/php/rule.adoc

48 lines
862 B
Plaintext

``++$this++`` refers to the current class instance. But static methods can be accessed without instantiating the class, and ``++$this++`` is not available to them. Using ``++$this++`` 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) {
// ...
}
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]