Convert a stdClass from a string back into a object in php

Might be a odd question as I cannot find any reference to this, but, I am using WordPress and creating a custom plugin, but, as I’m still developing it, its not installed, just built within the WordPress framework.

I have a stdClass which has been converted into a string and placed in localStorage. Here is what the string looks like:

Read More
> stdClass Object ( [flow_uuid] => 178ee7f1-8708-417f-b5e6-970bab44ec37
> [flow] => 26929 [run] => 5034279 [contact] =>
> ec73659b-b270-453c-8170-c190667917d7 [completed] => [values] => Array
> ( ) [steps] => Array ( [0] => stdClass Object ( [node] =>
> 83e332e0-a456-449f-a4f6-cee688f9395b [arrived_on] =>
> 2015-10-12T07:30:30.342Z [left_on] => 2015-10-12T07:30:30.470Z [text]
> => Hello! Good Morning Mr T How's U This morning? [type] => A [value] => None ) [1] => stdClass Object ( [node] => f85ed8a8-e745-495e-8eaf-1e6cfdbadf97 [arrived_on] =>
> 2015-10-12T07:30:30.470Z [left_on] => [text] => [type] => R [value] =>
> None ) ) [created_on] => 2015-10-12T07:30:30.235Z [modified_on] =>
> 2015-10-12T07:30:30.250Z [expires_on] => [expired_on] => [runtime] =>
> 12 - 10 @ 07 hour [runComplete] => false )

The code in PHP is a loop, and looks like this:

 <td style="text-align: center">
     <a class="button" href="index.php/?page_id=954" name="view_runlist" rel="<?php print_r($time); ?>" >View</a>
 </td>

When the link (button) is clicked it fires this in Javascript:

jQuery(document).on('click', '[name=view_runlist]', function() {
    localStorage.setItem('time', jQuery(this).attr('rel'));
});

Then on the other linked page (page_id=954) I have this in PHP:

$time = "<script>document.write(localStorage.getItem('time'));</script>";

But this only gives me a string and i had been testing it with explode and str_split to try and get it back to an object.

Is there a way to convert a string back into an object, and be able to use it as an object ?

Thanks in advance

Related posts