This is kind of tricky.
First and foremost, if you want to pass exactly the same object to another script, why dont you include
it? Or create some function to run instead?
Second, why don't you create your object in that script? It would save you a lot of trouble.
If you absolutely have to pass the object to another script via shell_exec, you may use the serialize()
function, but there are a few caveats:
- Of course you have to escape it, e.g. with
escapeshellarg
- If your object contains any resources (such as
fopen
handle, directly or indirectly), they will not be serialized and thus you will lose them
- Your script must be aware of yout Google_Client class definition, and definition of any class that it contains reference to. Otherwise it will be unserialized as __PHP_Incomplete_Class and effectively unusable.
check the manual page serialize
serialize() handles all types, except the
resource-type. You can even serialize() arrays that contain references
to itself. Circular references inside the array/object you are
serializing will also be stored. Any other reference will be lost.
When serializing objects, PHP will attempt to call the member function
__sleep() prior to serialization. This is to allow the object to do any last minute clean-up, etc. prior to being serialized. Likewise,
when the object is restored using unserialize() the __wakeup() member
function is called.
and the one for unserialize
Note: unserialize_callback_func directive It's possible to set a
callback-function which will be called, if an undefined class should
be instantiated during unserializing. (to prevent getting an
incomplete object "__PHP_Incomplete_Class".) Use your php.ini,
ini_set() or .htaccess to define 'unserialize_callback_func'.
Everytime an undefined class should be instantiated, it'll be called.
To disable this feature just empty this setting.