SSilence / php-imap-client

a easy solution for simple IMAP email access in php
MIT License
268 stars 136 forks source link

PHP Fatal error: Cannot use object of type IncomingMessage as array #195

Open quangvi282 opened 6 years ago

quangvi282 commented 6 years ago

when i getmessages, it return this error ( emails[0]['id'] not valid)

mattparksjr commented 6 years ago

Can you please share your full error?

gurmiguel commented 6 years ago

Having the same problem.

It's related to what's in the docs in here (http://ssilence.github.io/php-imap-client/usage.html), in the line below: $imap->deleteMessage($emails[1]['id']);

The problem is that when we retrieve a message, for example using the getUnreadMessages method, it returns an array of SSilence\ImapClient\IncomingMessage, but the id property of this object is private, so we can't use it as and array, like the docs say, and can't use it as a property, 'cause it's private.

Just a getter would solve this problem.

For those who won't change the code and need it for now, could use the code below: $ref = new ReflectionClass(get_class($email)); $prop_id = $ref->getProperty('id'); $prop_id->setAccessible(true); $id = $prop_id->getValue($email);

Not the prettiest way, but solves the case where you don't want to change the source for an implementation or wait for the solution.

mattparksjr commented 6 years ago

Should be solved with https://github.com/SSilence/php-imap-client/commit/103a02c143d4fe028fdcdb56fa3413e8a02cd111