[PHP] unable to use vars in foreach

2004-11-14 Thread Jonathan Villa
I'm using PHP 5.0.2

Here is a snippet of my code

$post=$_POST;//this is actually happening in an include somewhere else and
autoprepended.  Works just fine.

$modules = simplexml_load_file(MODULES);

foreach ($modules-module as $mod) {
echo $mod-postName.'br';
if (isset($post[$mod-postName])) {
die('in post');

.

echo-ing the postName works just fine, but when I get to the checking
whether or not the val is set, I get the error:

Warning: Illegal offset type in unset in /var/www/.

If I replace $post[$mod-postName] with a hardcoded val, it works

$post['news']

The values of $mod-postName are names of checkboxes.

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



Re: [PHP] unable to use vars in foreach

2004-11-14 Thread Ryan King
 
On Sunday, November 14, 2004, at 08:24PM, Jonathan Villa [EMAIL PROTECTED] 
wrote:

$modules = simplexml_load_file(MODULES);


Are you certain that MODULES has been defined()? And what do you get when you 
print_r($modules)?

-ryan

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



Re: [PHP] unable to use vars in foreach [updated question]

2004-11-14 Thread Jonathan Villa
So, searching php.net (I swear I did before...)

I found this at http://us2.php.net/language.types.array

 You cannot use arrays or objects as keys. Doing so will result in a
warning: Illegal offset type.

Neverthought that my var was an object, just thought maybe a string.  My
new question is, how can I convert this object to a string?  Or get the
val of it

Here is my XML

module name=News
postNamenews/postName
pageLevelPermissionsNews : Add
   authenticatedPagenews.add.php/authenticatedPage
   navDisplay page=/news/news.add.phpAdd/navDisplay
/pageLevelPermissions
pageLevelPermissionsNews : Current
   authenticatedPagenews.current.php/authenticatedPage
   navDisplay page=/news/news.current.phpCurrent/navDisplay
/pageLevelPermissions
pageLevelPermissionsNews : Archived
   authenticatedPagenews.archived.php/authenticatedPage
   navDisplay page=/news/news.archived.phpArchived/navDisplay
/pageLevelPermissions
/module

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



Re: [PHP] unable to use vars in foreach

2004-11-14 Thread Jonathan Villa

 On Sunday, November 14, 2004, at 08:24PM, Jonathan Villa [EMAIL PROTECTED]
 wrote:

$modules = simplexml_load_file(MODULES);


 Are you certain that MODULES has been defined()? And what do you get when
 you print_r($modules)?

 -ryan


Yes MODULES is defined.  It's defined in an include file.  In my loop,
when I echo the $mod-postName the values print just fine.  My issue is in
the conditional.

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



Re: [PHP] unable to use vars in foreach

2004-11-14 Thread Ryan King

On Sunday, November 14, 2004, at 08:36PM, Jonathan Villa [EMAIL PROTECTED] 
wrote:


 On Sunday, November 14, 2004, at 08:24PM, Jonathan Villa [EMAIL PROTECTED]
 wrote:

$modules = simplexml_load_file(MODULES);


 Are you certain that MODULES has been defined()? And what do you get when
 you print_r($modules)?

 -ryan


Yes MODULES is defined.  It's defined in an include file.  In my loop,
when I echo the $mod-postName the values print just fine.  My issue is in
the conditional.

AHA!

Here's what I think's going on (sorry I don't have time to investigate it 
myself)

$mod-postName is a simplexml object.  Due to some php5 magic, when used it a 
situation that calls for a string (like echo $xmlobj), it echos the proper 
value. However, when using it as an array subscript does not appear to qualify 
as this situation. To solve this try either:

$post[(string)$xmlobj]
OR
$post[strval($xmlobj)]

I hope this is clear and helpful.

-ryan

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



Re: [PHP] unable to use vars in foreach [updated question]

2004-11-14 Thread Ryan King
 
On Sunday, November 14, 2004, at 08:44PM, Jonathan Villa [EMAIL PROTECTED] 
wrote:

So, searching php.net (I swear I did before...)

I found this at http://us2.php.net/language.types.array

 You cannot use arrays or objects as keys. Doing so will result in a
warning: Illegal offset type.

Neverthought that my var was an object, just thought maybe a string.  My
new question is, how can I convert this object to a string?  Or get the
val of it

See my post from about 1 minute ago.

-ryan

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



Re: [PHP] unable to use vars in foreach

2004-11-14 Thread Jonathan Villa

ah yes thanks both worked...

I had written a function to this... I knew there had to be a much easier
way!!!


 On Sunday, November 14, 2004, at 08:36PM, Jonathan Villa [EMAIL PROTECTED]
 wrote:


 On Sunday, November 14, 2004, at 08:24PM, Jonathan Villa
 [EMAIL PROTECTED]
 wrote:

$modules = simplexml_load_file(MODULES);


 Are you certain that MODULES has been defined()? And what do you get
 when
 you print_r($modules)?

 -ryan


Yes MODULES is defined.  It's defined in an include file.  In my loop,
when I echo the $mod-postName the values print just fine.  My issue is
 in
the conditional.

 AHA!

 Here's what I think's going on (sorry I don't have time to investigate it
 myself)

 $mod-postName is a simplexml object.  Due to some php5 magic, when used
 it a situation that calls for a string (like echo $xmlobj), it echos the
 proper value. However, when using it as an array subscript does not appear
 to qualify as this situation. To solve this try either:

 $post[(string)$xmlobj]
 OR
 $post[strval($xmlobj)]

 I hope this is clear and helpful.

 -ryan


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