@@ -304,7 +304,13 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(zval *op, bo
304
304
case IS_TRUE :
305
305
return 1 ;
306
306
case IS_DOUBLE :
307
- return zend_dval_to_lval_safe (Z_DVAL_P (op ));
307
+ if (!is_long_compatible (Z_DVAL_P (op ))) {
308
+ zend_error (E_DEPRECATED , "Implicit conversion to int from non-compatible float" );
309
+ if (UNEXPECTED (EG (exception ))) {
310
+ * failed = 1 ;
311
+ }
312
+ }
313
+ return zend_dval_to_lval (Z_DVAL_P (op ));
308
314
case IS_STRING :
309
315
{
310
316
zend_uchar type ;
@@ -333,7 +339,13 @@ static zend_never_inline zend_long ZEND_FASTCALL zendi_try_get_long(zval *op, bo
333
339
* We use use saturating conversion to emulate strtol()'s
334
340
* behaviour.
335
341
*/
336
- return zend_dval_to_lval_cap_safe (dval );
342
+ if (!is_long_compatible (dval )) {
343
+ zend_error (E_DEPRECATED , "Implicit conversion to int from non-compatible float-string" );
344
+ if (UNEXPECTED (EG (exception ))) {
345
+ * failed = 1 ;
346
+ }
347
+ }
348
+ return zend_dval_to_lval_cap (dval );
337
349
}
338
350
}
339
351
case IS_OBJECT :
@@ -452,6 +464,7 @@ ZEND_API void ZEND_FASTCALL convert_to_long(zval *op) /* {{{ */
452
464
case IS_LONG :
453
465
break ;
454
466
case IS_DOUBLE :
467
+ // TODO Use safe variant?
455
468
ZVAL_LONG (op , zend_dval_to_lval (Z_DVAL_P (op )));
456
469
break ;
457
470
case IS_STRING :
@@ -800,6 +813,13 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_lax) /* {{
800
813
case IS_LONG :
801
814
return Z_LVAL_P (op );
802
815
case IS_DOUBLE :
816
+ if (EXPECTED (!is_lax )) {
817
+ if (!is_long_compatible (Z_DVAL_P (op ))) {
818
+ zend_error (E_DEPRECATED , "Implicit conversion to int from non-compatible float" );
819
+ // TODO Need to handle this here?
820
+ //if (UNEXPECTED(EG(exception))) {}
821
+ }
822
+ }
803
823
return zend_dval_to_lval (Z_DVAL_P (op ));
804
824
case IS_STRING :
805
825
{
@@ -816,11 +836,15 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_lax) /* {{
816
836
* We use saturating conversion to emulate strtol()'s
817
837
* behaviour.
818
838
*/
819
- /* For (int) casts */
820
- if (UNEXPECTED (is_lax )) {
821
- return zend_dval_to_lval_cap (dval );
822
- }
823
- return zend_dval_to_lval_cap_safe (dval );
839
+ /* Most usages are expected to not be (int) casts */
840
+ if (EXPECTED (!is_lax )) {
841
+ if (!is_long_compatible (dval )) {
842
+ zend_error (E_DEPRECATED , "Implicit conversion to int from non-compatible float-string" );
843
+ // TODO Need to handle this here?
844
+ //if (UNEXPECTED(EG(exception))) {}
845
+ }
846
+ }
847
+ return zend_dval_to_lval_cap (dval );
824
848
}
825
849
}
826
850
case IS_ARRAY :
@@ -1453,6 +1477,7 @@ ZEND_API zend_result ZEND_FASTCALL bitwise_not_function(zval *result, zval *op1)
1453
1477
ZVAL_LONG (result , ~Z_LVAL_P (op1 ));
1454
1478
return SUCCESS ;
1455
1479
case IS_DOUBLE :
1480
+ // TODO Handle manually in case deprecation notice promoted to Exception?
1456
1481
ZVAL_LONG (result , ~zend_dval_to_lval_safe (Z_DVAL_P (op1 )));
1457
1482
return SUCCESS ;
1458
1483
case IS_STRING : {
0 commit comments