Skip to content

Commit f9d8906

Browse files
rudi-augmentclaude
andcommitted
Fix PHP 8.3 and 8.4 compatibility
- Swap handler init order: call zend_object_std_init before setting custom handlers, as PHP 8.3 overwrites the handlers pointer during init - Rename Override test class to CustomNumber to avoid PHP 8.3 reserved name - Add explicit nullable type syntax for PHP 8.4 deprecation warnings Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 056947f commit f9d8906

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/decimal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ static php_decimal_t *php_decimal_alloc()
6868

6969
// TODO we should still go through everything to check for branch prediction.
7070
if (obj) {
71-
obj->std.handlers = &php_decimal_handlers;
7271
zend_object_std_init((zend_object *) obj, php_decimal_decimal_ce);
72+
obj->std.handlers = &php_decimal_handlers;
7373
} else {
7474
php_decimal_memory_error();
7575
}

src/rational.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ static php_rational_t *php_decimal_rational_alloc()
6969
php_rational_t *obj = ecalloc(1, sizeof(php_rational_t));
7070

7171
if (EXPECTED(obj)) {
72-
obj->std.handlers = &php_decimal_rational_handlers;
7372
zend_object_std_init((zend_object *) obj, php_decimal_rational_ce);
73+
obj->std.handlers = &php_decimal_rational_handlers;
7474
} else {
7575
php_decimal_memory_error();
7676
}

tests/Number/helpers/Number.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ public function shiftr($places): \Decimal\Number
8484
return new static($this->value / (10 ** $places));
8585
}
8686

87-
public function round(int $places = NULL, int $mode = NULL): \Decimal\Number
87+
public function round(?int $places = NULL, ?int $mode = NULL): \Decimal\Number
8888
{
8989
return new static($this->toDecimal(\Decimal\Decimal::MAX_PRECISION)->round($places, $mode)->toString());
9090
}
9191

92-
public function toFixed(int $places = NULL, bool $commas = NULL, int $mode = NULL): string
92+
public function toFixed(?int $places = NULL, ?bool $commas = NULL, ?int $mode = NULL): string
9393
{
9494
return new static($this->toDecimal(\Decimal\Decimal::MAX_PRECISION)->toFixed($places, $commas, $mode));
9595
}

tests/Number/json.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ var_dump(json_encode(Number::valueOf("0.3")));
99
/**
1010
* Test that we can override the internal alias.
1111
*/
12-
class Override extends Number
12+
class CustomNumber extends Number
1313
{
1414
public function jsonSerialize(): string
1515
{
1616
return "*";
1717
}
1818
}
1919

20-
var_dump(json_encode(Override::valueOf(5)));
20+
var_dump(json_encode(CustomNumber::valueOf(5)));
2121

2222
?>
2323
--EXPECT--

0 commit comments

Comments
 (0)