You are here: Re: [PHP] Strange array access problem « PHP « IT news, forums, messages
Re: [PHP] Strange array access problem

Posted by Robert Cummings on 10/26/05 08:06

> On Wed, 2005-10-26 at 00:28, Ken Tozier wrote:
> > I'm having a major problem with what seems, on it's face, to be a
> > really basic array function.
> >
> > What happens is on the browser end, I've written some javascript code
> > that packages up javascript variables in native PHP format and sends
> > the packed variables to a PHP script on the server via a POST and
> > XMLHTTP. On the server end, the PHP script grabs the packed variables
> > out of the $_POST, strips slashes and uses the "unserialize" command.
> >
> > Here's the function that gets the post data
> > $unpacked_data = GetDataFromPOST();
> >
> > And here's a var_dump of $unpacked_data as it appears in the browser
> > array(1) { ["handler"]=> array(1) { ["0"]=> string(9)
> > "databases" } }
> >
> > I'm able to get the "handler with no problem like so:
> > $parts = $unpacked_data['handler'];
> >
> > Which yields the following var_dump
> > array(1) { ["0"]=> string(9) "databases" }

Then later that day I wrote:
> But no matter what I did I could NOT get var_dump to dump my 0 key for
> the 'databases' as you have in your output. So methinks therein may lie
> your problem. Perhaps during the serialization in javascript check if
> the key is an integer-like string and if so then convert to an integer
> for the key serialization.

I did some more investigating. Your problem appears to be PHP5 specific.
I manually created the serialize string I assumed you had, but PHP4 was
smarter than me and auto converted the string key to an integer once
again; however, PHP5 for some reason during unserialization maintained
the string type for the key, however it was not able to access the value
because upon attempting to access the value I'm assuming it did a type
conversion to integer... additionally I got the following error notice
when trying to access the value:

<b>Notice</b>: Undefined index: 0 in <b>/home/suds/foo.php</b> on line
<b>25</b><br />
NULL

The following can duplicated the error:

$ser = 'a:1:{s:1:"0";s:3:"foo";}';
$unser = unserialize( $ser );
var_dump( $unser );
var_dump( $unser['0'] );

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. |
`------------------------------------------------------------'

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация