diff --git a/resources/posts/2024/2024-05-01-how-adding-type-declarations-makes-your-code-dangerous.md b/resources/posts/2024/2024-05-01-how-adding-type-declarations-makes-your-code-dangerous.md index fd9a53c95e5..29e107582fe 100644 --- a/resources/posts/2024/2024-05-01-how-adding-type-declarations-makes-your-code-dangerous.md +++ b/resources/posts/2024/2024-05-01-how-adding-type-declarations-makes-your-code-dangerous.md @@ -27,7 +27,7 @@ It looks like very modern PHP, right? But what if we pass some values: $price = new Price('100.82', '2'); ``` -What will be the price's first value? We'd love to see `100.82` float, right? +What will be the price value? We'd love to see `100.82` float, right? This is what our code really does ([see 3v4l.org](https://3v4l.org/lKgfG)): @@ -46,7 +46,7 @@ return (int) $value + (string) $anotherValue + (float) $thirdValue; Seeing it like this is an obvious red flag, but without using `declare(strict_types=1)`, PHP will silently continue. If we're lucky and we have enabled deprecation warning to trigger errors, we might see: ```bash -Deprecated: Implicit conversion from float-string "100.82" to int loses precision in /in/lKgfG on line 5 +Deprecated: Implicit conversion from float-string "100.82" to int loses precision on line 5 ``` But this is usually lost because we must run our tests with enabled deprecation warnings.