Re: [PHP] Debug/Learn Recursion of an Object

2006-05-18 Thread Graham Anderson

I got it :)

just put a print_r at each step of the function
like:  print_r($part->$parts);

thanks

g



On May 18, 2006, at 11:59 AM, Robert Cummings wrote:


On Thu, 2006-05-18 at 14:11, Graham Anderson wrote:

I am a bit new to Objects and Recursion
Any push in the right direction is appreciated

Generated from Pear's mimedecode, I have an object whose print_r is:
http://www.siren.cc/dev/object.txt


The function below will correctly traverse the object and find the
'correct' node.
Unfortunately, it is a little beyond my understanding at present. :(

Is there a way to debug the below function to echo how it is
traversing the object ?
For example, how would I echo the key names  and values while it is
traversing ?


http://www.php.net/manual/en/control-structures.foreach.php

Right smack at the top in the grey box. In the future please try  
reading

the manual. This is simplistic question that any newbie should know
having read the manual.

Cheers,
Rob.
--
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Debug/Learn Recursion of an Object

2006-05-18 Thread Robert Cummings
On Thu, 2006-05-18 at 14:11, Graham Anderson wrote:
> I am a bit new to Objects and Recursion
> Any push in the right direction is appreciated
> 
> Generated from Pear's mimedecode, I have an object whose print_r is:
> http://www.siren.cc/dev/object.txt
> 
> 
> The function below will correctly traverse the object and find the  
> 'correct' node.
> Unfortunately, it is a little beyond my understanding at present. :(
> 
> Is there a way to debug the below function to echo how it is  
> traversing the object ?
> For example, how would I echo the key names  and values while it is  
> traversing ?

http://www.php.net/manual/en/control-structures.foreach.php

Right smack at the top in the grey box. In the future please try reading
the manual. This is simplistic question that any newbie should know
having read the manual.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Debug/Learn Recursion of an Object

2006-05-18 Thread Graham Anderson

I am a bit new to Objects and Recursion
Any push in the right direction is appreciated

Generated from Pear's mimedecode, I have an object whose print_r is:
http://www.siren.cc/dev/object.txt


The function below will correctly traverse the object and find the  
'correct' node.

Unfortunately, it is a little beyond my understanding at present. :(

Is there a way to debug the below function to echo how it is  
traversing the object ?
For example, how would I echo the key names  and values while it is  
traversing ?


The hope is that something will click and I'll finally wrap my brain  
around this


many thanks





function getBody(&$part, $primary = 'text', $secondary = 'plain')
{
$body = false;


if (is_array($part)) {

foreach($part as $subpart) {
if (! $body = getBody($subpart, $primary, $secondary)) {
continue;
} else {
return $body;

}
}

} else {

if (isset($part->parts)) {

return getBody($part->parts, $primary, $secondary);

} else {

if ($part->ctype_primary == $primary && $part->ctype_secondary ==  
$secondary) {

return($part->body);
}

}
}
return $body;
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php