Cannot use object of type stdClass as array

I get the following error when submitting a form that processes a payment by phone.

Fatal error: Cannot use object of type stdClass as array in /export/home/www.domain.com/htdocs/checkpayment.php on line 4

What is the problem here? Can this error message be about the includes?
<? include("includes/global.inc.php");
include("functions.php");
include("menu.php");
$advert_id =  $_SESSION['advert']['advert_id'];

Open in new window

LVL 13
R7AFAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dinu_sorinCommented:
$advert_id =  $_SESSION['advert']->advert_id;//i guess $_SESSION['advert'] is an object.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
profyaCommented:
The following will tell:
echo "<pre>";
print_r($_SESSION['advert']);
var_dump($_SESSION['advert']);

Open in new window

0
dinu_sorinCommented:
well, since the $_SESSION can't normaly be an object, then the type of ['advert'] index is obvious
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

profyaCommented:
Try:
$advert_id =  $_SESSION['advert']->advert_id';
0
profyaCommented:
Sorry, there was a mistake. Make sure that advert_id is a member of your class.
$advert_id =  $_SESSION['advert']->advert_id;

Open in new window

0
R7AFAuthor Commented:
Thanks! I got it working.
0
dinu_sorinCommented:
@R7AF: i'm glad i could help. Happy coding!

@profya: try not to say same sugestion as other ppl did. You may stole their deserved points.
0
profyaCommented:
I read all posts dinu_sorin, I wonder how this happens. I do respect fellows, may be the slashes (advert_id;//i guess $_SESSION['advert'] is an object.) made me unfocused. I am in hurry, 4,000 points to be a master, may be this is the second reason for the rush. Sorry man. I'll focus much more in the future.
0
dinu_sorinCommented:
no worry :) i tought u did it on porpuse. Good luck at making your points ^_^.
0
profyaCommented:
Thanks dinu_sorin :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.