krowinski / php-mysql-replication

Pure PHP Implementation of MySQL replication protocol. This allow you to receive event like insert, update, delete with their data and raw SQL queries.
MIT License
323 stars 98 forks source link

Argument #1 ($array) must be of type array, bool given #110

Closed dominiquegerber closed 8 months ago

dominiquegerber commented 9 months ago

Please provide the following details.

Steps required to reproduce the problem.

Decoding of a date field.

Expected Result.

The decoded date field

Actual Result.

Analysis

The offending line in RowEvent.php : if (array_sum(DateTime::getLastErrors()) > 0) {

which produces the (fatal) error

> array_sum expects its parameter to be an array
> DateTime::getLastErrors() on the other hand returns either an array, or a boolean (false).
> 

This is due to a change in the return type of DateTime::getLastErrors in PHP8.2 as indicated in the official documentation: (https://www.php.net/manual/en/datetimeimmutable.getlasterrors.php) :

8.2.0 Before PHP 8.2.0, this function did not return false when there were no warnings or errors. Instead, it would always return the documented array structure.

I imagine that a simple cast to array should solve this issue, (array )false produces an empty array which would "array_sum" to 0.

DZunke commented 8 months ago

I had this too, but it was fixed within the current version 8 of the library.

dominiquegerber commented 8 months ago

Good to know thanks. Unfortunately version 8 of the lib requires to use symphony 7 as well, which we haven't migrated to yet. Ahh damn domino effect !

DZunke commented 8 months ago

Yeah and i do not fully understand why the compatibility to Symfony 6 should not be there anymore 🤔 Maybe one should try it with symfony constraints to ^6.0|^7.0 in composer file and if it works open a PR to re-enable wider symfony version constraints.

DZunke commented 8 months ago

Ok. I did it.

https://github.com/krowinski/php-mysql-replication/pull/113

Let's see if it gets merged.

krowinski commented 8 months ago

merged