1 | <?php |
||
15 | class ComparisonConstraint implements ConstraintInterface |
||
16 | { |
||
17 | public const OPERATOR_EQ = '='; |
||
18 | public const OPERATOR_NEQ = '!='; |
||
19 | public const OPERATOR_GT = '>'; |
||
20 | public const OPERATOR_GTE = '>='; |
||
21 | public const OPERATOR_LT = '<'; |
||
22 | public const OPERATOR_LTE = '<='; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $operator; |
||
28 | |||
29 | /** |
||
30 | * @var Version |
||
31 | */ |
||
32 | protected $operand; |
||
33 | |||
34 | /** |
||
35 | * @var array |
||
36 | */ |
||
37 | private static $validOperators = [ |
||
38 | self::OPERATOR_EQ, |
||
39 | self::OPERATOR_NEQ, |
||
40 | self::OPERATOR_GT, |
||
41 | self::OPERATOR_GTE, |
||
42 | self::OPERATOR_LT, |
||
43 | self::OPERATOR_LTE, |
||
44 | ]; |
||
45 | |||
46 | 15 | public function __construct(string $operator, Version $operand) |
|
55 | |||
56 | 11 | public static function fromString(string $constraintString) : ConstraintInterface |
|
66 | |||
67 | 5 | public function getOperator() : string |
|
71 | |||
72 | 5 | public function getOperand() : Version |
|
76 | |||
77 | 10 | public function assert(Version $version) : bool |
|
94 | } |
||
95 |
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: