Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

delphi-php-serializer

Create serialized PHP structs with Delphi

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

delphi-php-serializer

Create serialized PHP structs with Delphi

What does this do?

It solves a problem I had some time ago. I wanted to build structs in Delphi/Object Pascal which could be deserialized on PHP side. It's nothing much, but maybe somebody out there has exactly this problem too, and saves a bit time. My pleasure.

Can you demonstrate?

Sure.

pascal
var
serializer : TPHPSerializer;
begin
serializer := TPHPSerializer.Create();
serializer.Clear();
pascal
serializer.ArrayStart(Length(obj.configs));
for sw := 0 to Length(obj.configs) - 1 do
begin
  serializer.AddInt(sw); // array index!
  serializer.CreateClass('EQUIP_LEVELUP_CONFIG_config_t', 3);
  serializer.AddField('req_exp');
  serializer.AddInt(obj.configs[sw].req_exp);
  serializer.AddField('addon_group');
  serializer.AddInt(obj.configs[sw].addon_group);
  serializer.AddField('money_cost');
  serializer.AddInt(obj.configs[sw].money_cost);
  serializer.CloseClass;
end;
serializer.CloseClass; // close array

Result can then be retrieved by:

pascal
serializer.GetFinalSWON();

You can then use this string with unserialize() PHP call, and like magic, have the object you described with delphi.

Cheers.