tags:

views:

50

answers:

1

Note: I have tried using unserialize function but it say that first argument should be an string and not an Object and so my question -

Q: How can I unserialize an ArrayObject in php, my ArrayObject contains:

O:11:"ArrayObject":2:{s:14:"shoppingBasket";a:1:{s:6:"offers";a:2:{i:10;a:8:{s:9:"object_id";s:2:"10";s:6:"family";s:8:"Internet";s:8:"is_unica";b:1;s:10:"offer_type";s:6:"Atomic";s:24:"product_specification_id";s:6:"134455";s:20:"contract_constraints";a:5:{s:19:"min_contract_period";s:1:"1";s:13:"notice_period";s:2:"12";s:15:"rollover_period";s:1:"1";s:18:"right_of_wd_period";s:1:"1";s:19:"cancellation_period";s:6:"ALWAYS";}s:15:"financial_terms";a:3:{s:14:"billing_period";a:2:{i:0;s:6:"YEARLY";i:1;s:9:"QUARTERLY";}s:14:"payment_method";a:1:{i:0;s:12:"DIRECT_DEBIT";}s:17:"bill_presentation";a:1:{i:0;s:5:"PAPER";}}s:6:"prices";a:1:{i:25;a:1:{s:9:"object_id";s:2:"25";}}}i:11224;a:8:{s:9:"object_id";s:5:"11224";s:6:"family";s:8:"Internet";s:8:"is_unica";b:0;s:10:"offer_type";s:11:"DOUBLE_PLAY";s:24:"product_specification_id";s:5:"32567";s:20:"contract_constraints";a:5:{s:19:"min_contract_period";s:1:"8";s:13:"notice_period";s:1:"2";s:15:"rollover_period";s:1:"6";s:18:"right_of_wd_period";s:1:"1";s:19:"cancellation_period";s:12:"END_OF_MONTH";}s:15:"financial_terms";a:3:{s:14:"billing_period";a:2:{i:0;s:6:"YEARLY";i:1;s:9:"QUARTERLY";}s:14:"payment_method";a:1:{i:0;s:12:"DIRECT_DEBIT";}s:17:"bill_presentation";a:1:{i:0;s:5:"PAPER";}}s:6:"prices";a:0:{}}}}s:15:"recommendations";a:1:{i:10017;a:7:{s:9:"object_id";s:5:"10017";s:10:"offer_type";s:6:"Atomic";s:6:"family";s:0:"";s:8:"is_unica";b:0;s:15:"financial_terms";a:3:{s:14:"billing_period";a:1:{i:0;s:9:"QUARTERLY";}s:14:"payment_method";a:1:{i:0;s:12:"DIRECT_DEBIT";}s:17:"bill_presentation";a:1:{i:0;s:5:"PAPER";}}s:20:"contract_constraints";a:5:{s:19:"min_contract_period";i:24;s:19:"cancellation_period";s:6:"ALWAYS";s:13:"notice_period";i:3;s:15:"rollover_period";i:2;s:18:"right_of_wd_period";i:1;}s:6:"prices";a:1:{i:99;a:1:{s:9:"object_id";s:2:"99";}}}}}

Here is the code which gives this serialized output and I want to unserialize it.

private function associateCollateral($entities)
            {
                    //var_dump($entities);

                    // Extract all object ids from the given set of ids, and pass into the getContentId.
                    $content_ids = $this->getCollateralDao()->getContentId(array_keys($entities->offsetGet('recommendations')));
                    // Call to CMS to get collateral content.
                    /*foreach($content_ids as $content_id)
                    {
                             $contentObj = CmsObjectHandler::get(OBJECT_TYPE_CONTENT,$content_id);
                             $content = $contentObj->getContent();
                             $result += $content;
                             echo"Here \n";
                             print_r($result)."\n";
                             //exit();
                    }*/
                    var_dump($entities);  ---STEP1
                    return $entities;     ---STEP2
                    //var_dump($entities);  ---STEP3
                    //exit();
            }

Step 2 returns serialized output and now I want to unserialize it.

A: 

UPDATE

K, so I tried this:

$something = '/*(enter your string here)*/';

echo print_r(unserialize($something));

And it came out as an arrayObject like it was supposed to. Just make sure you're passing unserialize the string representation of the arrayObject rather than the arrayObject itself.

munch
I have added chunk of code which returns serialized data and now I want to unserialize it.
Rachel
Rachel. This is an extension of your other question here http://stackoverflow.com/questions/1997156/php-error-vardumpa-shows-different-value-and-return-a-prints-out-different/1997243#1997243. Find where the data is serialised first and fix that. by trying to sidestep the issue you arent solving it just avoiding it but similar issues will popup and you will be back to scratch
DeveloperChris
@DC: I tried but there are no var_dump, echo or print_r as such which would print out the serialized data output. I will again go through it and update.
Rachel
I have tried all suggestions again but still am getting that serialized form of data.
Rachel
@Rachel, where's the code you're using to serialize?
munch
@munch:Basically the serialized data is present in the database and when we pass the content ID than it would go and look for content relevant to that content id and there exists than if would get it from the database and display it. But the thing is I have commented out the code which would get content from database and even than am getting serialized data and so am not sure why it is happening so. Hope am making some sense here ?
Rachel
From what I understood of that (=P), and what I see being output, it's not the Content ID's that is what's serialized, but rather it's `$entities`. I suggest following the trail of that variable and seeing where it comes from.
munch