1 | <?php |
||
7 | class RationalNumber |
||
8 | { |
||
9 | const REGEX_FRACTION = '#^(?P<sign>[+-]?)(?P<numerator>[0-9]+)(/(?P<denominator>[0-9]+))?$#'; |
||
10 | |||
11 | /** |
||
12 | * @var int |
||
13 | */ |
||
14 | private $numerator; |
||
15 | |||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | private $denominator; |
||
20 | |||
21 | /** |
||
22 | * @var bool |
||
23 | */ |
||
24 | private $negative; |
||
25 | |||
26 | /** |
||
27 | * @param int $numerator |
||
28 | * @param int $denominator |
||
29 | * @param bool $negative |
||
30 | * @throws InvalidArgumentException |
||
31 | */ |
||
32 | public function __construct($numerator, $denominator, $negative) |
||
42 | |||
43 | /** |
||
44 | * @return bool |
||
45 | */ |
||
46 | public function isFraction() |
||
50 | |||
51 | /** |
||
52 | * @return int |
||
53 | */ |
||
54 | public function getNumerator() |
||
58 | |||
59 | /** |
||
60 | * @return int |
||
61 | */ |
||
62 | public function getDenominator() |
||
66 | |||
67 | /** |
||
68 | * @return boolean |
||
69 | */ |
||
70 | public function isNegative() |
||
74 | |||
75 | /** |
||
76 | * @param string $value |
||
77 | * @return RationalNumber |
||
78 | * @throws InvalidArgumentException |
||
79 | */ |
||
80 | public static function fromString($value) |
||
92 | |||
93 | /** |
||
94 | * @param self $number |
||
95 | * @return string |
||
96 | */ |
||
97 | public static function toString(self $number) |
||
108 | |||
109 | /** |
||
110 | * @return string |
||
111 | */ |
||
112 | public function __toString() |
||
116 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: