|
Posted by bill on 06/15/07 18:23
Captain Paralytic wrote:
> On 14 Jun, 11:14, bill <nob...@spamcop.net> wrote:
>>> On Jun 13, 9:19 pm, bill <nob...@spamcop.net> wrote:
>>>> Turning on error_reporting(E_ALL); was quite an eye opener as to
>>>> how much "fixing" PHP will do for the sloppy coder.
>>>> I fixed all of the errors except:
>>>> Notice: Undefined property: parts in
>>>> /ContactManagement/contact_mainpage.php on line 120
>>>> where the line in question is:
>>>> $parts = $struct->parts;
>>>> where $struct = = imap_fetchstructure($in, $mid);
>>>> $struct is an object, parts is an array of objects
>>>> what would the correct syntax of the statement be ?
>>>> bill
>> petersprc wrote:
>>
>> > If you var_dump($struct) right before that line, what do you
>> see? It's
>> > probably false or otherwise invalid. Maybe because it wasn't
>> defined
>> > or the imap function had a problem.
>>
>> here is the dump
>> object(stdClass)(12) { ["type"]=> int(0) ["encoding"]=> int(0)
>> ["ifsubtype"]=> int(1) ["subtype"]=> string(5) "PLAIN"
>> ["ifdescription"]=> int(0) ["ifid"]=> int(0) ["lines"]=>
>> int(2) ["bytes"]=> int(27) ["ifdisposition"]=> int(0)
>> ["ifdparameters"]=> int(0) ["ifparameters"]=> int(1)
>> ["parameters"]=> array(2) { [0]=> object(stdClass)(2) {
>> ["attribute"]=> string(7) "CHARSET" ["value"]=> string(10)
>> "ISO-8859-1" } [1]=> object(stdClass)(2) { ["attribute"]=>
>> string(6) "FORMAT" ["value"]=> string(6) "flowed" } } }- Hide quoted text -
>>
>> - Show quoted text -
>
> So there you have the answer, parts is not listed.
>
Well, that was simple.
in a 1 part message, parts is empty.
Ok, I will ignore that error because in the next line I check to
see if $parts is empty
Can anyone suggest a way of writing this so that the Notice error
would not pop up when parts does not exist - or is it worth it to
write super clean code ?
Here is the code segment:
$struct = imap_fetchstructure($in, $mid);
$parts = $struct->parts;
$i = 0;
if (!$parts) { /* Simple message, only 1 piece */
$attachment = array(); /* No attachments */
$content = imap_body($in,$mid );
}
else { /* Complicated message, multiple parts */
stuff-------
}
bill
Navigation:
[Reply to this message]
|