tags:

views:

64

answers:

1

I have a function which would query database and get content if it exists for particular id and in there I have this Piece of Code:

var_dump($a); ---STEP 1
return $a     ---STEP 2
var_dump($a); ---STEP 3
exit();       ---STEP 4

When I do var_dump($a), it gives me ---STEP 1

    object(ArrayObject)[67]
  public 'shoppingBasket' => 
    array
      'offers' => 
        array
          10 => 
            array
              ...
          11224 => 
            array
              ...
  public 'recommendations' => 
    array
      10017 => 
        array
          'object_id' => string '10017' (length=5)
          'offer_type' => string 'Atomic' (length=6)
          'family' => string '' (length=0)
          'is_unica' => boolean false
          'financial_terms' => 
            array
              ...
          'contract_constraints' => 
            array
              ...
          'prices' => 
            array
              ...

as $a is of ArrayObject type but when I use return $a and than var_dump($a) than it gives me --- STEP 3

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";}}}}}

I am not sure why its happening this way, normally if we have content in database for particular id than we query the database and get the content for that particular id.

Q: But am not sure why am getting different values for $a in here, any suggestions ?

Q: How can I unserialize the STEP 3 output in php. I have tried using unserialize function but its not working.

Thanks.

Update:

Here is the function which is calling associateCollateral function:

  public function getOfferById($id, $raw = FALSE)
        {
                $offers = $this->getOfferDao()->getByID($id);
                $offer_count = $offers->count();
                //var_dump($offer_count);
                //exit();
                // Throw an exception if no results were found.
                if (!$offers->count())
                {
                        throw new Exception("No offers were found while searching for ids: {$id}.");
                }

                if (!$raw)
                {
                        $offers = $this->validateOffers($offers);
                }


                // Associate collateral content with offers to send back.
                return $this->associateCollateral($offers);
                //$val = $this->associateCollateral($offers);
                //echo "Here is the value of Associate Collateral \n";
                //var_dump($val);
                //exit();

        }

Here is the associateCollateral Function, when the associateCollateral function is called than it would go and check into collateral content database and will look if the provided content id has some collateral content and if it does than it would go and get the collateral content.

  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();
        }
A: 

It seems I don't have enough reputation to Comment. So this is not an answer but a request for more information.

Simply put its not possible for PHP to serialise the data out of thin air. something between the return from your function eg return $a; (step 2) and the var_dump($a) (step 3) call is serialising the data.

You will need to provide a larger snippet of the code including the call to the function and whatever happens after the call to that function and before var_dump (step 3)

Do you call var_dump immediately after the function return? Is the function called via another function?

DC

Ok

Step 3 is never executed in associateCollateral(). I had wondered if your original question was just shortened or an error

            var_dump($entities);  ---STEP1
            return $entities;     ---STEP2 <== function is exited  
            var_dump($entities);  ---STEP3 <== never executed
            //exit();

This means the echo you are seeing with the serialised output is from another part of your code

DC

There is another print statement somewhere in your code displaying the serialised data. Comment out all the var_dump statements and run it again. My guess is that the serialised data will still be output. Don't forget serialised data is merely a string so it can be output by an echo or print statement which could be anywhere in your code. Probably somewhere after the getOfferById() function is called.

If the serialised data is not output after commenting out the var_dump statements, then re-enable each one one at a time until the serialised data re-appears. but this scenario is highly unlikely given the information you have provided

DC

DeveloperChris
Yes function is called via another function. I will post complete snippet of code in here.
Rachel
I have updated the code, now I have getOffersbyId which is the calling function and associateCollateral function which is called by getOffersbyId.
Rachel
I comment out return entities and than if I do var_dump($entities) than it does give me the serialized data output instead of giving me the ArrayObject Structure and I wonder why it is happening that way.
Rachel
if you commented out the return $entities line then you have 2 var_dump($entities); in succession. it is impossible to have the data serialised between the two there is another echo or vardump occuring else where which is causing you confusion.uncomment the exit(); to make sure your program quits immediately after the var_dump() (step 3) so no more dumps or echo's can occur.
DeveloperChris
I am still getting serialized data output after removing step 3 var_dump. So step 1 gives arrayobject, step 2 returns serialized data output.
Rachel
I have re-checked exit properly and but still am having same issue with Serialized Data and ArrayObject.
Rachel
Ok. I will re-check the complete thing and update in here.
Rachel