Moln / 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
3 stars 3 forks source link

Warning: array_sum(): Addition is not supported on type array #20

Open kekstlt opened 3 months ago

kekstlt commented 3 months ago

Problem with migration to PHP8.3

In RowEvent.php line 728:

  [ErrorException]                                               
  Warning: array_sum(): Addition is not supported on type array 

$dateLastErrorsin this case is

array (
  'warning_count' => 1,
  'warnings' => 
  array (
    12 => 'The parsed date was invalid',
  ),
  'error_count' => 0,
  'errors' => 
  array (
  ),
)

So arrays now cant be summed with arrays

kekstlt commented 3 months ago

Patch

diff --git a/src/MySQLReplication/Event/RowEvent/RowEvent.php b/src/MySQLReplication/Event/RowEvent/RowEvent.php
index e20c6e9..607b387 100644
--- a/src/MySQLReplication/Event/RowEvent/RowEvent.php
+++ b/src/MySQLReplication/Event/RowEvent/RowEvent.php
@@ -683,7 +683,7 @@ class RowEvent extends EventCommon

         $date = DateTime::createFromFormat('YmdHis', $value)->format('Y-m-d H:i:s');
         $dateLastErrors = DateTime::getLastErrors();
-        if ($dateLastErrors && array_sum($dateLastErrors) > 0) {
+        if ($dateLastErrors && ($dateLastErrors['warning_count'] + $dateLastErrors['error_count']) > 0) {
             return null;
         }

@@ -725,7 +725,7 @@ class RowEvent extends EventCommon
             return null;
         }
         $dateLastErrors = DateTime::getLastErrors();
-        if ($dateLastErrors && array_sum($dateLastErrors) > 0) {
+        if ($dateLastErrors && ($dateLastErrors['warning_count'] + $dateLastErrors['error_count']) > 0) {
             return null;
         }