Skip to content

Commit df82fb9

Browse files
committed
Extract float to int deprecation message into own function
1 parent 5c7fa32 commit df82fb9

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Zend/zend_operators.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(zval *op, bo
307307
double dval = Z_DVAL_P(op);
308308
zend_long lval = zend_dval_to_lval(dval);
309309
if (!zend_is_long_compatible(dval, lval)) {
310-
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float %f", dval);
310+
zend_incompatible_double_to_long_error(dval);
311311
if (UNEXPECTED(EG(exception))) {
312312
*failed = 1;
313313
}
@@ -809,6 +809,11 @@ ZEND_API void ZEND_FASTCALL convert_to_object(zval *op) /* {{{ */
809809
}
810810
/* }}} */
811811

812+
void zend_incompatible_double_to_long_error(double d)
813+
{
814+
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float %f", d);
815+
}
816+
812817
ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict) /* {{{ */
813818
{
814819
try_again:
@@ -828,7 +833,7 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_strict) /*
828833
zend_long lval = zend_dval_to_lval(dval);
829834
if (UNEXPECTED(is_strict)) {
830835
if (!zend_is_long_compatible(dval, lval)) {
831-
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float %f", dval);
836+
zend_incompatible_double_to_long_error(dval);
832837
// TODO Need to handle this here?
833838
//if (UNEXPECTED(EG(exception))) {}
834839
}

Zend/zend_operators.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,13 @@ static zend_always_inline bool zend_is_long_compatible(double d, zend_long l) {
138138
return ((double)l == d);
139139
}
140140

141+
void zend_incompatible_double_to_long_error(double d);
142+
141143
static zend_always_inline zend_long zend_dval_to_lval_safe(double d)
142144
{
143145
zend_long l = zend_dval_to_lval(d);
144146
if (!zend_is_long_compatible(d, l)) {
145-
zend_error(E_DEPRECATED, "Implicit conversion to int from non-compatible float %f", d);
147+
zend_incompatible_double_to_long_error(d);
146148
}
147149
return l;
148150
}

0 commit comments

Comments
 (0)