Since $defaultColoursNames is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $defaultColoursNames 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...
290
}
291
292
/**
293
* Simple function to transform a 8-bit (256 colours) colour code
294
* to one of the default 8 colors available in the terminal
295
*/
296
public static function map256To8(int $colourCode) : string
Since $coloursMap is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $coloursMap 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...
299
throw new \InvalidArgumentException("Invalid colour code");
Since $coloursMap is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $coloursMap 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...
303
}
304
305
/**
306
* Check if $colour exists
307
* If it's a 256-colours code and $terminal doesn't support it, returns a fallback value
308
*/
309
public static function validateColour(Terminal $terminal, $colour, string $fallback = null)
310
{
311
if (is_int($colour)) {
312
if ($colour < 0 || $colour > 255) {
313
throw new \InvalidArgumentException("Invalid colour code");
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:In the case above, it makes sense to update
SomeClass
to useself
instead: