Array to string conversion on $folder_->messages()->all()->setFetchOrderDesc()->get();
When doing : $messages = $folder_->messages()->all()->setFetchOrderDesc()->get();
I sometimes get this error :
[26-Sep-2024 10:40:13 Europe/Paris] PHP Warning: Array to string conversion in /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Connection/Protocols/ImapProtocol.php on line 707 [26-Sep-2024 10:40:13 Europe/Paris] PHP Stack trace: [26-Sep-2024 10:40:13 Europe/Paris] PHP 1. {main}() /apache_sites/jbm/new_msg_retrieve_new_msg_php-imap.php:0 [26-Sep-2024 10:40:13 Europe/Paris] PHP 2. Webklex\PHPIMAP\Query\Query->get() /apache_sites/jbm/new_msg_retrieve_new_msg_php-imap.php:491 [26-Sep-2024 10:40:13 Europe/Paris] PHP 3. Webklex\PHPIMAP\Query\Query->curate_messages($available_messages = class Illuminate\Support\Collection { protected $items = [0 => [...]]; protected $escapeWhenCastingToString = FALSE }) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Query/Query.php:380 [26-Sep-2024 10:40:13 Europe/Paris] PHP 4. Webklex\PHPIMAP\Query\Query->populate($available_messages = class Illuminate\Support\Collection { protected $items = [0 => [...]]; protected $escapeWhenCastingToString = FALSE }) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Query/Query.php:316 [26-Sep-2024 10:40:13 Europe/Paris] PHP 5. Webklex\PHPIMAP\Query\Query->fetch($available_messages = class Illuminate\Support\Collection { protected $items = [0 => [...]]; protected $escapeWhenCastingToString = FALSE }) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Query/Query.php:347 [26-Sep-2024 10:40:13 Europe/Paris] PHP 6. Webklex\PHPIMAP\Connection\Protocols\ImapProtocol->flags($uids = [0 => [0 => 'OK', 1 => 'SEARCH', 2 => 'completed', 3 => [...]]], $uid = 1) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Query/Query.php:241 [26-Sep-2024 10:40:13 Europe/Paris] PHP 7. Webklex\PHPIMAP\Connection\Protocols\ImapProtocol->fetch($items = [0 => 'FLAGS'], $from = [0 => [0 => 'OK', 1 => 'SEARCH', 2 => 'completed', 3 => [...]]], $to = NULL, $uid = 1) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Connection/Protocols/ImapProtocol.php:841 [26-Sep-2024 10:40:13 Europe/Paris] PHP 8. implode($separator = ',', $array = [0 => [0 => 'OK', 1 => 'SEARCH', 2 => 'completed', 3 => [...]]]) /apache_sites/jbm/lib_8.2/vendor/webklex/php-imap/src/Connection/Protocols/ImapProtocol.php:707
Hi @Pascal76 , many thanks for your report. Are you still able to reproduce this with the latest release? If that's the case, please provide some more information as well as the latest stack trace and reopen this ticket :)
Best regards & happy coding,
waiting for the post 6.0 build, because you added some new changes. Will it be out today ?
This exception is thrown when the flags, headers, sizes or content method on the ImapProtocol.php is called with the $uids as an empty array. Because the fetch method checks if the $from is an array and filled with at least one item, the check fails and causes an Array to String conversion.
Still happens on version 6.1.0
Hi @Ruud-Gerrits , many thanks for the information. Any idea how I could replicate this issue and or how this could be tested and verified? :)
Best regards & happy coding,
Hi @Webklex.
Any idea how I could replicate this issue and or how this could be tested and verified? :)
For example, when working with pagination.
/**
* @var \Webklex\PHPIMAP\Client $client
* @var \Carbon\Carbon $date
*/
$client->getFolder('FOLDER_NAME')->messages()->since(date: $date)->limit(limit: 3, page: 2)->get();
When there are 0 or 1 letters on the second page. There are 3 or 4 emails in total.
If 0 (empty) on second page, then the error is: \Webklex\PHPIMAP\Exceptions\GetMessagesFailedException (Undefined array key 0) If 1 email on second page, then the error is: \Webklex\PHPIMAP\Exceptions\GetMessagesFailedException (Array to string conversion)
php: 8.4.2/8.4.3 webklex/php-imap: 6.1.0