Numeric types cannot perform cast or arithmetic operations on PHP 7.3+

Description

Due to PHP 7.3 internal changes, cast_object now requires to handle a new case _IS_NUMBER, otherwise performing cast or arithmetic on numeric type objects will see the following error:

Object of class Cassandra\Bigint could not be converted to number

The specific PHP internal change is the following:

cast_object() with _IS_NUMBER
The cast_object() object handler now also accepts the _IS_NUMBER type. The
handler should return either an integer or float value in this case,
whichever is more appropriate.

From: https://raw.githubusercontent.com/php/php-src/PHP-7.3/UPGRADING.INTERNALS

To make sure the numeric types can do type cast or arithmetic, it's required to update the cast_object implementation for those implements Numeric interface:

  • Cassandra\Smallint

  • Cassandra\Bigint

  • Cassandra\Tinyint

  • Cassandra\Varint

  • Cassandra\Float

  • Cassandra\Decimal

We can also reference the commit from PHP source https://github.com/php/php-src/commit/b2b2b43 on the internal change and how to potential fix the issue.

Environment

Cassandra server 3.0
PHP 7.4
Debian Buster
C++ driver 2.15.1

Pull Requests

None

Activity

Michael Penick 
May 19, 2020 at 12:53 PM

Hi, Thanks for reporting! It sounds like you have a good handle on how to fix this issue. Would you be able to create a pull request to fix it?

Details

Assignee

Reporter

Reproduced in

Fix versions

Priority

Created March 27, 2020 at 11:28 AM
Updated June 11, 2020 at 12:26 PM