I am having a weird problem echoing out a session array. I would like to accomplish the following:
for($i=0;$i<sizeof($_SESSION['medication']);$i++){
echo $_SESSION['medication'][$i];
}
In fact it echoes out all fields of the array and then afterwards displays the well known error message "Catchable fatal error: Object of class stdClass could not be converted to string".
However, when I just echo out field 0 all the time in the loop instead of field $i, it works fine without error message.
Why is there an error message triggered?
UPDATE 1
var_dump($_SESSION['medication']) echoes out a bunch of stuff:
array(12) { [0]=> string(1) "1" [1]=> int(10) [2]=> string(2) "14" [3]=> string(2) "17" [4]=> object(stdClass)#1 (7) { ["id"]=> string(1) "1" ["name"]=> string(9) "AUGMENTIN" ["strength"]=> string(6) "875 mg" ["sig"]=> string(29) "1 tablet by mouth twice a day" ["quantity"]=> string(6) "twenty" ["refills"]=> string(4) "zero" ["treatmentfor"]=> string(17) "sinus, bronchitis" } [5]=> object(stdClass)#2 (7) { ["id"]=> string(2) "10" ["name"]=> string(8) "DIFLUCAN" ["strength"]=> string(6) "150 mg" ["sig"]=> string(47) "1 tablet by mouth as needed for yeast infection" ["quantity"]=> string(3) "one" ["refills"]=> string(3) "one" ["treatmentfor"]=> string(27) "yeast, other abx for female" } [6]=> object(stdClass)#3 (7) { ["id"]=> string(2) "14" ["name"]=> string(14) "MEDROL DOSEPAK" ["strength"]=> string(1) "-" ["sig"]=> string(135) "6 PO Qday x 1 day, then 5 PO Qday x 1 day, then 4 PO Qday x 1 day, then 3 PO Qday x1 day, then 2 PO Qday x 1 day then 1 PO Qday x 1 day" ["quantity"]=> string(2) "21" ["refills"]=> string(4) "zero" ["treatmentfor"]=> string(17) "allergic rhinitis" } [7]=> object(stdClass)#4 (7) { ["id"]=> string(2) "17" ["name"]=> string(23) "FLUTICASONE NASAL SPRAY" ["strength"]=> string(6) "0.0005" ["sig"]=> string(91) "1 spray each nostril twice a day, reducing to 1 spray per nostril per day when appropriate." ["quantity"]=> string(10) "one bottle" ["refills"]=> string(3) "one" ["treatmentfor"]=> string(17) "allergic rhinitis" } [8]=> object(stdClass)#5 (7) { ["id"]=> string(1) "1" ["name"]=> string(9) "AUGMENTIN" ["strength"]=> string(6) "875 mg" ["sig"]=> string(29) "1 tablet by mouth twice a day" ["quantity"]=> string(6) "twenty" ["refills"]=> string(4) "zero" ["treatmentfor"]=> string(17) "sinus, bronchitis" } [9]=> object(stdClass)#6 (7) { ["id"]=> string(2) "10" ["name"]=> string(8) "DIFLUCAN" ["strength"]=> string(6) "150 mg" ["sig"]=> string(47) "1 tablet by mouth as needed for yeast infection" ["quantity"]=> string(3) "one" ["refills"]=> string(3) "one" ["treatmentfor"]=> string(27) "yeast, other abx for female" } [10]=> object(stdClass)#7 (7) { ["id"]=> string(2) "14" ["name"]=> string(14) "MEDROL DOSEPAK" ["strength"]=> string(1) "-" ["sig"]=> string(135) "6 PO Qday x 1 day, then 5 PO Qday x 1 day, then 4 PO Qday x 1 day, then 3 PO Qday x1 day, then 2 PO Qday x 1 day then 1 PO Qday x 1 day" ["quantity"]=> string(2) "21" ["refills"]=> string(4) "zero" ["treatmentfor"]=> string(17) "allergic rhinitis" } [11]=> object(stdClass)#8 (7) { ["id"]=> string(2) "17" ["name"]=> string(23) "FLUTICASONE NASAL SPRAY" ["strength"]=> string(6) "0.0005" ["sig"]=> string(91) "1 spray each nostril twice a day, reducing to 1 spray per nostril per day when appropriate." ["quantity"]=> string(10) "one bottle" ["refills"]=> string(3) "one" ["treatmentfor"]=> string(17) "allergic rhinitis" } }
UPDATE 2
I have found the problem: later in the code I use the variable $medication which seems to refer to the session. How come? Is register_globals on?
UPDATE 3 - SOLUTION FOUND register_globals was indeed on (how embarrassing) and I turned it off. It related to the other variable $medication. Now it works fine. Thanks to everyone!
var_dump($_SESSION['medication'])please. Thanks.var_dump($_SESSION['medication']);