Something strange happening with arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Larry Woods
Forum Newbie
Posts: 2
Joined: Wed Jul 26, 2006 9:44 am

Something strange happening with arrays

Post by Larry Woods »

I am trying to load Wordpress onto a linux server. When I execute the following 'for each':

print_r($this->roles);
foreach ($this->roles as $role => $data) {
I get:

Warning: Invalid argument supplied for foreach() in /home/ourposition/blogs/wp-includes/capabilities.php on line 19

so I added the print_r, to see what was in the 'roles' array. Here is what I get (abbreviated):

a:5:{s:13:\"administrator\";a:2:{s:4:\"name\";s:13:\"Administrator\";s:12:\"capabilities\";a:30:{s:13:\"switch_themes\";b:1;s:11:\"edit_themes\";b:1;s:16:\"activate_plugins\";b:1;s:12:\

so I run EXACTLY the same code on my local XP system. First, no warning, and as you would expect the print_r looks like this (abbreviated):

Array ( [administrator] => Array ( [name] => Administrator [capabilities] => Array ( [switch_themes] => 1 [edit_themes] => 1 [activate_plugins] => 1 [edit_plugins] => 1 [edit_users] => 1 [edit_files] => 1 [manage_options] => 1 [moderate_comments] => 1 [manage_categories] => 1

It looks like, under linux, the print_r is dumping out a "internal" format of the array. Is this an indication of what the problem is?

Thanks for any help because the Wordpress install is "virgin"; i.e., no changes, and the Wordpress people brag about how it is a "foolproof" installation that takes a matter of minutes. Nope!

Larry Woods
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Take a look at..

Code: Select all

unserialize();
Larry Woods
Forum Newbie
Posts: 2
Joined: Wed Jul 26, 2006 9:44 am

Post by Larry Woods »

Sorry, Guru, but I am not a PHP expert, so I apologize for my ignorance but I don't see what the "serialize" function has to do with the fact that the code runs under Windows but doesn't run under Linux. Same code. Is there some PHP option that needs to be set differently?

Thanks for your patience...

Larry Woods
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I don't see why it would do that either, but I know it's a serialized string, and unserialize will turn it back into an array..

Code: Select all

$array = unserialize($string);
Post Reply