Solved

Cannot use object of type stdClass as array

Posted on 2009-07-15
10
1,211 Views
Last Modified: 2012-05-07
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

0
Comment
Question by:R7AF
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 2

Accepted Solution

by:
dinu_sorin earned 500 total points
ID: 24857944
$advert_id =  $_SESSION['advert']->advert_id;//i guess $_SESSION['advert'] is an object.
0
 
LVL 14

Expert Comment

by:profya
ID: 24858074
The following will tell:
echo "<pre>";
print_r($_SESSION['advert']);
var_dump($_SESSION['advert']);

Open in new window

0
 
LVL 2

Expert Comment

by:dinu_sorin
ID: 24858293
well, since the $_SESSION can't normaly be an object, then the type of ['advert'] index is obvious
0
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
LVL 14

Expert Comment

by:profya
ID: 24858330
Try:
$advert_id =  $_SESSION['advert']->advert_id';
0
 
LVL 14

Expert Comment

by:profya
ID: 24858346
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
 
LVL 13

Author Closing Comment

by:R7AF
ID: 31603653
Thanks! I got it working.
0
 
LVL 2

Expert Comment

by:dinu_sorin
ID: 24858466
@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
 
LVL 14

Expert Comment

by:profya
ID: 24858496
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
 
LVL 2

Expert Comment

by:dinu_sorin
ID: 24858521
no worry :) i tought u did it on porpuse. Good luck at making your points ^_^.
0
 
LVL 14

Expert Comment

by:profya
ID: 24858540
Thanks dinu_sorin :)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question