-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect parse of integer values for double vars (#1024)
Values like `{"a": 101}` were parsed incorrectly during JSON parsing. They're internally interpreted as being integer and during assignment to double variable it were bit-casted from `int` to `double`, which is wrong. This PR fixes this behavior. Now integer values are converted to double explicitly.
- Loading branch information
Showing
2 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
require_once 'kphp_tester_include.php'; | ||
|
||
class MoneyRequest { | ||
private float $amount; | ||
|
||
public function __construct(float $amount) { | ||
$this->amount = $amount; | ||
} | ||
|
||
public function getAmount(): float { | ||
return $this->amount; | ||
} | ||
} | ||
|
||
function test_json_float_read(): void { | ||
$raw = '{"amount":101}'; | ||
|
||
$res = JsonEncoder::decode($raw, MoneyRequest::class); | ||
var_dump($res->getAmount()); | ||
} | ||
|
||
test_json_float_read(); |