Another alternative would be to use `convert_scalar_to_number_ex()` here, which imho matches the expected behavior most closely: Casting to the closest of long/double. As @smalyshev pointed out that would change the behavior for strings as well, but I think that's for the best (you know, all that talk about PHP handling numeric strings and numbers the same way; should honor that).

```c
long result;
convert_scalar_to_number_ex(&retval_ptr);
switch (Z_TYPE_P(retval_ptr)) {
    case IS_LONG:
        result = ZEND_NORMALIZE_BOOL(Z_LVAL_P(retval_ptr));
        break;
    case IS_DOUBLE:
        result = ZEND_NORMALIZE_BOOL(Z_DVAL_P(retval_ptr));
        break;
    case IS_ARRAY:
        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Comparison function returned invalid value");
        result = zend_hash_num_elements(Z_ARRVAL_P(retval_ptr)) != 0; /* nod to BC */
}
zval_ptr_dtor(&retval_ptr);
return result;
```