Since $instance is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $instance to at least protected.
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the getSomeVariable() on that sub-class, you will receive
a runtime error:
classYourSubClassextendsYourClass{}YourSubClass::getSomeVariable();// Will cause an access error.
In the case above, it makes sense to update SomeClass to use self instead:
classSomeClass{privatestatic$someVariable;publicstaticfunctiongetSomeVariable(){returnself::$someVariable;// self works fine with private.}}
Loading history...
16
1
self::$instance = new Str($str);
17
}
18
19
1
return self::$instance;
20
}
21
22
/**
23
* Limpiar la cadena y almacenar.
24
*
25
* @param $str string Cadena de caracteres a limpiar.
26
*
27
* @return void
28
*/
29
1
private function set($str)
30
{
31
1
$str = html_entity_decode($str);
32
1
$str = str_replace("\xc2\xa0", "", $str);
33
1
$str = trim($str);
34
1
$str = preg_replace("!\s+!", " ", $str);
35
36
1
$this->str = $str;
37
1
}
38
39
/**
40
* Limpiar una cadena de caracteres.
41
*
42
* @param string $str Cadena de caracteres a limpiar.