#1 2015-12-04 07:20:19

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Red /write PHP serialization

Hi,

This is  not  a strictly mORM-ot related question, but could be seen as possible feautre request. smile


Is there any library to work with  standard PHP serialized strings? This is how the serialized data looks like :

a:5:{s:8:"pa_meret";a:7:{s:4:"name";s:8:"pa_meret" ....

Leslie

Offline

#2 2015-12-04 07:30:01

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Re: Red /write PHP serialization

I am looking into mORMot's serialization if there is an easy way to create a custom serialization for this. Some guidelines/examples could be useful. smile

Last edited by Leslie7 (2015-12-04 07:32:34)

Offline

#3 2015-12-04 07:47:52

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Red /write PHP serialization

A custom serializer would not help, since the main issue would be the use of ";" of ",".

Offline

#4 2015-12-04 08:07:26

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Re: Red /write PHP serialization

ab,

Is there a deeper level entry point to start from for an alternate serialization? Is it a far strached attempt to create one if time is on short supply right now?

Offline

#5 2015-12-04 08:23:19

hnb
Member
Registered: 2015-06-15
Posts: 290

Re: Red /write PHP serialization

Just use json_encode and json_decode for PHP instead of serialize/unserialize.

Last edited by hnb (2015-12-04 08:23:37)


best regards,
Maciej Izak

Offline

#6 2015-12-04 08:40:20

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Re: Red /write PHP serialization

I have no control over the php code on the server side. I just need to access  the data in the database created by php serialization in my pascal code.

Offline

#7 2015-12-04 09:55:38

Leslie7
Member
Registered: 2015-06-25
Posts: 248

Re: Red /write PHP serialization

The PHP format is not that far from json. The major differences seem to be:

- the name -value  pairs are separated by ";" instead of ":"
- there is a metadata prefix included everywhere. Eg
     - for both the name and value : <datatype>:<datasize>
            eg:  JSON : {"aName":"aValue"}   
          PHP: {s:5:"aName";s:6:"aValue")
     - for the collections/arrays       : <a>:<element_count>
          eg a:5{ ... }

This is the the syntax to be used:

String
s:size:value;

Integer
i:value;

Boolean
b:value; (does not store "true" or "false", does store '1' or '0')

Null
N;

Array
a:size:{key definition;value definition;(repeated per element)}

Object
O:strlen(object name):object name:object size:{s:strlen(property name):property name:property definition;(repeated per property)}

String values are always in double quotes
Array keys are always integers or strings
    "null => 'value'" equates to 's:0:"";s:5:"value";',
    "true => 'value'" equates to 'i:1;s:5:"value";',
    "false => 'value'" equates to 'i:0;s:5:"value";',
    "array(whatever the contents) => 'value'" equates to an "illegal offset type" warning because you can't use an
    array as a key; however, if you use a variable containing an array as a key, it will equate to 's:5:"Array";s:5:"value";',
     and
    attempting to use an object as a key will result in the same behavior as using an array will.

Last edited by Leslie7 (2015-12-04 15:05:55)

Offline

Board footer

Powered by FluxBB