@@ -346,11 +346,49 @@ static int php_phongo_int64_compare_objects(zval* o1, zval* o2)
346
346
}
347
347
348
348
#if PHP_VERSION_ID < 80000
349
+ static int php_phongo_int64_compare_with_other_type (zval * object , zval * value )
350
+ {
351
+ zval tmp_value ;
352
+ zval result ;
353
+ int ret ;
354
+
355
+ if (Z_OBJ_HT_P (object )-> cast_object (object , & tmp_value , ((Z_TYPE_P (value ) == IS_FALSE || Z_TYPE_P (value ) == IS_TRUE ) ? _IS_BOOL : Z_TYPE_P (value ))) == FAILURE ) {
356
+ zval_ptr_dtor (& tmp_value );
357
+ return 1 ;
358
+ }
359
+
360
+ compare_function (& result , & tmp_value , value );
361
+
362
+ ret = Z_LVAL (result );
363
+ zval_ptr_dtor (& tmp_value );
364
+ zval_ptr_dtor (& result );
365
+
366
+ return ret ;
367
+ }
368
+
349
369
static int php_phongo_int64_compare_zvals (zval * result , zval * op1 , zval * op2 )
350
370
{
351
- ZVAL_LONG (result , php_phongo_int64_compare_objects (op1 , op2 ));
371
+ /* Happy case: compare an int64 object with another object, long, or double */
372
+ if ((php_phongo_int64_is_int64_object (op1 ) || php_phongo_int64_is_long_or_double (op1 )) && (php_phongo_int64_is_int64_object (op2 ) || php_phongo_int64_is_long_or_double (op2 ))) {
373
+ ZVAL_LONG (result , php_phongo_int64_compare_objects (op1 , op2 ));
374
+ return SUCCESS ;
375
+ }
376
+
377
+ /* When comparing an int64 object with any other type, cast the int64 object to the desired type.
378
+ * We know that if op1 is an object, op2 has to be the other type and vice versa. For op2 being
379
+ * the object, we can again flip the values used for comparison and multiply the result with -1. */
380
+
381
+ if (php_phongo_int64_is_int64_object (op1 )) {
382
+ ZVAL_LONG (result , php_phongo_int64_compare_with_other_type (op1 , op2 ));
383
+ return SUCCESS ;
384
+ }
385
+
386
+ if (php_phongo_int64_is_int64_object (op2 )) {
387
+ ZVAL_LONG (result , -1 * php_phongo_int64_compare_with_other_type (op2 , op1 ));
388
+ return SUCCESS ;
389
+ }
352
390
353
- return SUCCESS ;
391
+ return FAILURE ;
354
392
}
355
393
#endif
356
394
0 commit comments