Giter Site home page Giter Site logo

Comments (10)

Sean-Der avatar Sean-Der commented on July 1, 2024

Hey @rybakit

So AFAIK the zend engine API shouldn't care about order. While they are stored as a list, I do not think the position+key matters.
However, zero length keys does seem edge casey to me (I know we do have tests for this though)

I am debugging this now, and will update it when I know more.


What value are you expecting back after deserialization? If you are encoding/decoding in multiple languages you should also be setting PHPONLY to false, then you will end up with the following

$msgpack = new MessagePack();
$msgpack->setOption(MessagePack::OPT_PHPONLY, false);
var_dump($msgpack->unpack( hex2bin('82c0a8737464436c617373a3666f6fa3626172')));
var_dump($msgpack->unpack( hex2bin('82a3666f6fa3626172c0a8737464436c617373')));

----

Warning: [msgpack] (msgpack_unserialize_map_item) illegal key type in /home/vagrant/code/msgpack-php/test.php on line 5
array(2) {
  [""]=>
  string(8) "stdClass"
  ["foo"]=>
  string(3) "bar"
}

Warning: [msgpack] (msgpack_unserialize_map_item) illegal key type in /home/vagrant/code/msgpack-php/test.php on line 6
array(2) {
  ["foo"]=>
  string(3) "bar"
  [""]=>
  string(8) "stdClass"
}

Or are you looking to create PHP objects via input crafted from Lua? While possible, that is certainly an undefined behavior. Looking at the code it could be done, but would be expensive once you hit the null key (containing the class name) you would then have to copy your half serialized object to the new object. If you are really stuck I can look into making this work for you, but you are depending on funky behavior.

from msgpack-php.

rybakit avatar rybakit commented on July 1, 2024

Hey @Sean-Der, thanks for the quick response.
I'm trying to get back a php object. The combo looks like this:

$packer = new MessagePack(true);
$packed = $packer->pack((object) ['foo' => 'bar']); 
// 0x82c0a8737464436c617373a3666f6fa3626172

Then the packed data goes through Lua:

unpacked = msgpack.decode(packed)
packed = msgpack.encode(unpacked) 
-- 0x82a3666f6fa3626172c0a8737464436c617373

And returns to php:

$obj = $packer->unpack($packed);
var_dump($obj);
// class stdClass#3 (0) {}

from msgpack-php.

rybakit avatar rybakit commented on July 1, 2024

would be expensive once you hit the null key (containing the class name) you would then have to copy your half serialized object to the new object.

What if you serialize an object into indexed array ['stdClass', ['foo' => 'bar']]? This will guarantee the same order across different languages, but introduce a BC break and I don’t know if it’s worth it. Or store the data into a temporary structure before building an object?

If you are really stuck I can look into making this work for you, but you are depending on funky behavior.

I try to figure out first what is possible in my case. If you say that it will be funky to support the object serialization, then I will probably just drop supporting objects in my code.

from msgpack-php.

Sean-Der avatar Sean-Der commented on July 1, 2024

Hey @rybakit try 488779b for PHP5 and 116cc56 for PHP7

from msgpack-php.

rybakit avatar rybakit commented on July 1, 2024

Works like a charm πŸ‘ Thank you!

from msgpack-php.

Sean-Der avatar Sean-Der commented on July 1, 2024

Awesome! Now I just need some tests. Hand crafting these would not be fun, is there anything special you did to make your test values? I just want to make test values for

  • Multiple properties
  • Some before/some after so the empty key is in the middle
  • All datatypes strings/numbers/arrays/objects

thanks!

from msgpack-php.

rybakit avatar rybakit commented on July 1, 2024

@Sean-Der Please check #61.

from msgpack-php.

Sean-Der avatar Sean-Der commented on July 1, 2024

Thank you so much @rybakit , I owe you big time πŸ‘ I am gonna go grok the tests and the merge them thank you so much!

from msgpack-php.

rybakit avatar rybakit commented on July 1, 2024

Happy to help, and thank you too ;)

from msgpack-php.

rybakit avatar rybakit commented on July 1, 2024

@Sean-Der @laruence Looks like the fix for this issue is not present in the latest versions (neither 0.5.7 nor 2.0.0). Do you plan to create a new tag with the fix anytime soon?

from msgpack-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.