@@ -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 :
@@ -807,6 +820,13 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_lax) /* {{
807
820
case IS_LONG :
808
821
return Z_LVAL_P (op );
809
822
case IS_DOUBLE :
823
+ if (EXPECTED (!is_lax )) {
824
+ if (!is_long_compatible (Z_DVAL_P (op ))) {
825
+ zend_error (E_DEPRECATED , "Implicit conversion to int from non-compatible float" );
826
+ // TODO Need to handle this here?
827
+ //if (UNEXPECTED(EG(exception))) {}
828
+ }
829
+ }
810
830
return zend_dval_to_lval (Z_DVAL_P (op ));
811
831
case IS_STRING :
812
832
{
@@ -823,11 +843,15 @@ ZEND_API zend_long ZEND_FASTCALL zval_get_long_func(zval *op, bool is_lax) /* {{
823
843
* We use saturating conversion to emulate strtol()'s
824
844
* behaviour.
825
845
*/
826
- /* For (int) casts */
827
- if (UNEXPECTED (is_lax )) {
828
- return zend_dval_to_lval_cap (dval );
829
- }
830
- return zend_dval_to_lval_cap_safe (dval );
846
+ /* Most usages are expected to not be (int) casts */
847
+ if (EXPECTED (!is_lax )) {
848
+ if (!is_long_compatible (dval )) {
849
+ zend_error (E_DEPRECATED , "Implicit conversion to int from non-compatible float-string" );
850
+ // TODO Need to handle this here?
851
+ //if (UNEXPECTED(EG(exception))) {}
852
+ }
853
+ }
854
+ return zend_dval_to_lval_cap (dval );
831
855
}
832
856
}
833
857
case IS_ARRAY :
@@ -1460,6 +1484,7 @@ ZEND_API zend_result ZEND_FASTCALL bitwise_not_function(zval *result, zval *op1)
1460
1484
ZVAL_LONG (result , ~Z_LVAL_P (op1 ));
1461
1485
return SUCCESS ;
1462
1486
case IS_DOUBLE :
1487
+ // TODO Handle manually in case deprecation notice promoted to Exception?
1463
1488
ZVAL_LONG (result , ~zend_dval_to_lval_safe (Z_DVAL_P (op1 )));
1464
1489
return SUCCESS ;
1465
1490
case IS_STRING : {
0 commit comments