Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:10:52+00:00 2026-06-04T15:10:52+00:00

I am having a weird problem echoing out a session array. I would like

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:10:53+00:00Added an answer on June 4, 2026 at 3:10 pm

    My guess is that you have something other than a string stored in that index of the session array. In this case, it seems you have a stdClass object in the array.

    Also, since you can have non-numeric array indices, using a foreach loop will yield better results.

    foreach($_SESSION['medication'] as $index => $value) {
        if (is_scalar($value)) {
            echo "$index = $value<br />";
        } else {
            echo "<pre>$index = " . print_r($value, true) . "</pre><br />";
        }
    }
    

    is_scalar will check to see if the variable can be echo’ed (string, int, float, bool), otherwise we will print_r the value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a weird problem with the following function, which returns a string with
I'm having a weird problem, I have the following code in my page.php template
I'm having a weird problem right now. I'm trying to iron out a CSS
I am having one weird problem.I am getting time of the day like 800
I'm having the weird problem that after having javascript inject some dom-elements the css-rules
I'm having a weird problem with memset, that was something to do with a
I'm having a weird problem with index organized table. I'm running Oracle 11g standard.
I am having a weird problem with sending data back to my server. This
I am having a weird problem where lots of ^M characters show up in
I'm having a weird problem with avr-gcc. If I do this: int i =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.