|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-12-12 02:16 UTC] develar at gmail dot com
Description:
------------
Object type after encode/decode is lost. Only first item in associative array is save. If the array not associative all works, but is necessary an associative array.
Reproduce code:
---------------
<?php
class Types_authenticator_admin_cms
{
public $attributes;
}
class Attribute_authenticator_admin_cms
{
public $name;
}
$result = unserialize('O:29:"Types_authenticator_admin_cms":1:{s:10:"attributes";a:3:{i:50;a:1:{i:0;O:33:"Attribute_authenticator_admin_cms":1:{s:4:"name";s:4:"Name";}}i:13;a:2:{i:0;O:33:"Attribute_authenticator_admin_cms":1:{s:4:"name";s:4:"Name";}i:1;O:33:"Attribute_authenticator_admin_cms":1:{s:4:"name";s:4:"Text";}}i:1;a:1:{i:0;O:33:"Attribute_authenticator_admin_cms":1:{s:4:"name";s:4:"Name";}}}}');
echo "before encode/decode\n\n";
print_r($result);
echo "\n\nafter encode/decode\n\n";
$big_endian = pack('d', 1) == "\0\0\0\0\0\0\360\77" ? 2 : 0;
print_r(amf_decode(amf_encode($result, $big_endian | 1), $big_endian));
?>
Expected result:
----------------
before encode/decode
Types_authenticator_admin_cms Object
(
[attributes] => Array
(
[50] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
)
[13] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
[1] => Attribute_authenticator_admin_cms Object
(
[name] => Text
)
)
[1] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
)
)
)
after encode/decode
Types_authenticator_admin_cms Object
(
[attributes] => stdClass Object
(
[50] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
)
[13] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
[1] => Attribute_authenticator_admin_cms Object
(
[name] => Text
)
)
[1] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
)
)
)
Actual result:
--------------
before encode/decode
Types_authenticator_admin_cms Object
(
[attributes] => Array
(
[50] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
)
[13] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
[1] => Attribute_authenticator_admin_cms Object
(
[name] => Text
)
)
[1] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
)
)
)
after encode/decode
Types_authenticator_admin_cms Object
(
[attributes] => stdClass Object
(
[50] => Array
(
[0] => Attribute_authenticator_admin_cms Object
(
[name] => Name
)
)
[13] => Array
(
[0] => stdClass Object
(
[name] => Name
)
[1] => stdClass Object
(
[name] => Text
)
)
[1] => Array
(
[0] => stdClass Object
(
[name] => Name
)
)
)
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 19:00:01 2025 UTC |
No, the problem is different. During serializing of arrays the amf3_serialize_array function registers "completely" anonymous class without incrementing an internal counter of classes. This leads to difference between class indexes and their real position, which results in wrong decoding... To fix the issue, change the following (amf.c, line 1812): /* string array or not sequenced array => associativ */ /* if(num_count > 0 && (str_count > || max_index != num_count-1) */ if((str_count > 0 && num_count == 0) || (num_count > 0 && max_index != (int)num_count-1)) { amf3_write_objecthead(buf, AMF_INLINE_ENTITY|AMF_INLINE_CLASS|AMF_CLASS_DYNAMIC); var_hash->nextClassIndex++; amf3_write_emptystring(buf AMFTSRMLS_CC); /* classname=" */ "var_hash->nextClassIndex++;" has to be added....