1 | <?php |
||
5 | class Comparator |
||
6 | { |
||
7 | const DEFAULT_SCALE = 10; |
||
8 | |||
9 | /** |
||
10 | * The number of digits after the decimal place which will be used in the comparison. |
||
11 | * The scale will only be used if bccomp is available. Otherwise your system precision |
||
12 | * will be used. |
||
13 | * |
||
14 | * @var int |
||
15 | */ |
||
16 | private static $scale = self::DEFAULT_SCALE; |
||
17 | |||
18 | /** |
||
19 | * Compare two arbitrary precision numbers. This method will use bccomp for the comparison, |
||
20 | * or fall back to using standard comparison operators if ext-bcmath is not available. |
||
21 | * |
||
22 | * @param string|double|int $leftOperand |
||
23 | * @param string|double|int $rightOperand |
||
24 | * |
||
25 | * @return int Returns 0 if the two operands are equal, 1 if the left_operand is larger than the right_operand, |
||
26 | * -1 otherwise. |
||
27 | */ |
||
28 | 60 | public static function compare($leftOperand, $rightOperand) |
|
40 | |||
41 | /** |
||
42 | * Set the number of digits after the decimal place which will be used in the comparison. |
||
43 | * |
||
44 | * @param int $value |
||
45 | */ |
||
46 | 10 | public static function setScale($value) |
|
50 | } |
||
51 |
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: