Solved

Cannot use object of type stdClass as array

Posted on 2009-07-15
10
1,185 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
  • 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
What does $selected = $month == $beginning_month ? 'selected' : ''; mean? 5 39
What does this formatting equate to? 7 18
Currency in SQL? 2 29
PHP Curl to output a url 7 45
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

766 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