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...
289
}
290
291
/**
292
* Simple function to transform a 8-bit (256 colours) colour code
293
* to one of the default 8 colors available in the terminal
294
*/
295
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...
298
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...
301
}
302
303
/**
304
* Check if $colour exists
305
* If it's a 256-colours code and $terminal doesn't support it, returns a fallback value
306
*/
307
public static function validateColour(Terminal $terminal, $colour, string $fallback = null)
308
{
309
if (is_int($colour)) {
310
if ($colour < 0 || $colour > 255) {
311
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: