![]() |
Serializing Objects
Earlier, I was questioning Inverness concerning a few things and also leaning a few things from him concerning a system I wanted to create for a project. He suggested I create a way to serialize and un-serialize objects into strings.
It will be useful for the system I'm planning and required a bit of tweaking, but I decided it could be somewhat useful for the public. Use: These two functions are for turning the values of all the vars in an object into a long string. And vice versa. Credits:To Inverness, for the idea as well as quite a bit of help with the upper function. (I.E. Basically giving me the answer >_<, brain isn't functioning to well right now.) PHP Code:
|
You need to do temp.varname = 0; not temp.varname; =P
And the serializing is supposed to be specific to that type of object >_> Anyone could use savevarstoarray() to serialize any graal object. |
Thank god we all assume no strings EVER will use the ":" character.
|
Ideally your serialised string will have no bias towards certain characters. Like Novo said, your script will probably break if a string is used that contains the : character. It's safe to assume that variable names won't contain colons, so that makes it easier to process variable names, however the script needs to more reliably read the value.
The way that PHP does it is that your serialised string not only has the name and value of the object, but it also has a length value for the value. That way, you do not have to depend upon the positions of : characters. An example: foo:3:b:r:bar:4:ZOOM ... This would make a variable "foo" with the value "b:r", and another called "bar" with the value "ZOOM", because it's been instructed to read the 3 characters following the first instruction, and 4 characters for the second one, regardless of the position of colons in the string. |
Quote:
|
Well, it's been working so far on my end without any breakage Skyld. :O
|
Quote:
|
Quote:
Quote:
|
| All times are GMT +2. The time now is 08:58 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.