Skip to content

Arrays and negative index #83

@rlalak

Description

@rlalak

I found very strange error.
When I serialize array with only one negative index, one or more positive and without 0 index, serialization does not work properly.

Code

$test_array = array ( -1 => 'negative', 1 => 'positive', ); $test_array_packed = msgpack_pack($test_array); var_dump($test_array_packed); $test_array_unpacked = msgpack_unpack($test_array_packed); var_dump($test_array_unpacked); 

Output

string(20) "���positive�positive" array(3) { [0]=> NULL [1]=> string(8) "positive" [2]=> string(8) "positive" } 

If we add 0 index or other negative index serialization will work properly.

Kode

$test_array = array ( -1 => 'negative', -2 => 'other_negative', 1 => 'positive', ); $test_array_packed = msgpack_pack($test_array); var_dump($test_array_packed); $test_array_unpacked = msgpack_unpack($test_array_packed); var_dump($test_array_unpacked); 

Output

string(37) "���negative��other_negative��positive" array(3) { [-1]=> string(8) "negative" [-2]=> string(14) "other_negative" [1]=> string(8) "positive" } 

Kode

$test_array = array ( -1 => 'negative', 0 => 'other_negative', 1 => 'positive', ); $test_array_packed = msgpack_pack($test_array); var_dump($test_array_packed); $test_array_unpacked = msgpack_unpack($test_array_packed); var_dump($test_array_unpacked); 

Output

string(37) "���negative��other_negative��positive" array(3) { [-1]=> string(8) "negative" [0]=> string(14) "other_negative" [1]=> string(8) "positive" } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions