Click here to Skip to main content
14,825,162 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have no idea of this is a possible but...

If i serialize a object in C#, and save it.
Can i then load that serialized object into php?

PHP does not use datatypes, and C# has a variable type like that (forgot its name),
so i thought maybe its possible.

As for why, its mostly just to expand my knowledge.

Thanks for anyone who helps!!!

It would generally be far better to use a custom 'serialisation' process (i.e. making up a string that is easy to parse) than try to de-parse the .Net serialisation format (even the XML one) in another environment. Another responder mentioned JSON; it would also be fairly easy to have your C# code directly produce (and parse, if that is important to your solution) the PHP serialize() format, which is plain text.

Whether you want to actually make a custom serialiser in the .Net sense of the word or just have some methods on your shared class that read/write the appropriate text format is up to you, really.
Short answer: Yes, it is possible.

Middle-sized answer: What you are trying to do is going to teach you a lot about data formats (which is, I think, your aim). It will involve learning about the internal representations (in both languages) of the object and its members as well as the external (serialised) representation. Be prepared for a lot of low-level stuff - what we used to call bit-bashing in days of yore when we practiced it. :)

What you get (apart from useful knowledge) is going to be platform-dependent (machine architecture, compiler/interpreter, supported object types/members, etc) so it's not going to become a general purpose tool. But that's OK - you don't start metalwork by making a swiss army knife.

Best of luck!

If you think this is a good answer, mark it accepted. Vote anyway.
Yes, this is possible. The serialized data from C# could/would be called as a JSON formatted string, that could be understood by the PHP script. Refer to this question in SO:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900