Jump to content

One for the gurus: PHP5+ Multidimensional Associative Array Functionality Loss


thepip3r

Recommended Posts

I'm designing a menu system for my site and started building a multidimensional array like I always have; I went over and over this and don't think there's any syntax errors < PHP 5.whoKnows.  Here is what it looks like:

 

$menuArr['home']		= "<div $onMouseEvents><a href=\"index.php?a=middle\">&#187; Home</a></div>";
$menuArr['projects']	= "<div $onMouseEvents><a href=\"index.php?m=projects;\">&#187; Projects</a></div>";
$menuArr['resume']		= "<div $onMouseEvents><a href=\"resume.mht\" target=\"_new\">&#187; Resume</a></div>";
$menuArr['projects']['kix']		= "<div $onMouseEvents1><a href=\"index.php?m=projects;kix;\">&#187; KiX</a></div>";
$menuArr['projects']['hta']		= "<div $onMouseEvents1><a href=\"index.php?m=projects;hta;\">&#187; HTAs</a></div>";
$menuArr['projects']['php']		= "<div $onMouseEvents1><a href=\"index.php?m=projects;php;\">&#187; PHP</a></div>";
$menuArr['projects']['vbs']		= "<div $onMouseEvents1><a href=\"index.php?m=projects;vbs;\">&#187; VBScript</a></div>";
$menuArr['projects']['php']['nsconv']		= "<div $onMouseEvents2><a href=\"index.php?m=projects;php;&p=php;nsconv\">&#187; Number System Converter</a></div>";
$menuArr['projects']['php']['randpwgen']	= "<div $onMouseEvents2><a href=\"index.php?m=projects;php;&p=php;randpwgen\">&#187; Random Password Generator</a></div>";
$menuArr['projects']['php']['asciigen']		= "<div $onMouseEvents2><a href=\"index.php?m=projects;php;&p=php;asciigen\">&#187; ASCII Character Generator</a></div>";
$menuArr['projects']['php']['hexcolor']		= "<div $onMouseEvents2><a href=\"index.php?m=projects;php;&p=php;hexcolor\">&#187; Hex Color Chart</a></div>";

 

When I refreshed my page, I got an error stating: Fatal Error: cannot use string offset as an array in ....  After commenting my code vigorously to try and find the syntax error I thought I had, I decided to search the almighty Google and came up with this bug report off of Zend which is apparently no bug at all.  The commentary finally links us back to the PHP website for backwards incompatability for PHP 4 -> 5, 3rd bullet.

 

After reading this I wanted to choke myself.  One of the main reasons I LOVE PHP is because of it's awesome ease with working with arrays.  And if this associative multidimensional array building no longer works, I have two questions.

 

1.  Why would they make it that way? ...essentially they made an incredibly simple way to build multidimensional arrays and obfuscated the whole process.

2.  How do we now make multi-dim assoc. arrays so that they turn out the way they used to in PHP4??

 

e.g.

 

Array
(
    [.idleTime] => 1171284896
    [.loggedIn] => 1171284896
    [user] => Array
        (
            [user_id] => 1
            [username] => thepip3r
            [email] => [email protected]
            [sex] => ?
            [city] => ??
            [state] => ??
            [country] => ??
            [created] => 1162412158
            [lastlogon] => 1170776664
        )

    [char] => Array
        (
        .......
        )
)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.