Skip to content

stdClass #6

Description

@RedactedProfile

@divoxx

So apparently, and please forgive me as Ruby is still kind of lost on me, I'm forced to unserialize a previously PHP serialized data structure, which uses "stdClass" as an object, in this exact string:

O:8:"stdClass":1:{s:7:"Results";a:1:{i:0;O:8:"stdClass":2:{s:2:"Id";i:54;s:4:"Name";s:14:"This is a Name";}}}

which when I use PHPSerializer.load() on this data, I get:

unserializer.y:38:in `new': identifier stdClass needs to be constant (NameError)
    from unserializer.y:38:in `_reduce_13'
    from /var/lib/gems/1.9.1/gems/php-serialization-0.5.3/lib/php_serialization/tokenizer.rb:12:in `each'
    from /var/lib/gems/1.9.1/gems/racc-1.4.12/lib/racc/parser.rb:331:in `_racc_yyparse_c'
    from /var/lib/gems/1.9.1/gems/racc-1.4.12/lib/racc/parser.rb:331:in `yyparse'
    from unserializer.y:75:in `run'
    from /var/lib/gems/1.9.1/gems/php-serialization-0.5.3/lib/php_serialization.rb:16:in `load'
    from ser.rb:15:in `<main>'

From the looks of things here, it's because the Object name here stdClass, starts with a lower case letter. Which after a few hours of raw frustration (as a Ruby limitation of Structs I wasn't aware of) I finalyl deduced by instead calling it "StdClass" , which get's me:

unserializer.y:38: warning: redefining constant Struct::StdClass
#<struct Struct::StdClass Results={0=>#<struct Struct::StdClass Id=54, Name="This is a Name">}>

For now, I'm just going to have a run a string conversion to make sure all first letters are capitalized, as I am dealing with a situation where I cannot change the underlying data itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions