Call to undefined method stdClass

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Call to undefined method stdClass

Post by kendall »

Hi guys...

i have the following code that is loaded into an iframe.

Code: Select all

$page_content = isset($_SESSION['MenuItem'])? $_SESSION['MenuItem'] : new Page(); // $_SESSION is a populated new Page()


$column = isset($_GET['column'])? $_GET['column'] : 'left';
// submit information
if(isset($_GET['add_content'])){
	$content = array('contentid'=>$_GET['ContentID']
					,'contentname'=>$_GET['ContentName']
					,'filetype'=>$_GET['FileType']
					,'section'=>$_GET['Section']
					);
	//print_r($page_content);
	$page_content->add_column_content($content,$column,$order= false);
	
}
a $_GET['add_content'] is passed via a javascript initiated reload(iframe.src) of the iframe causing it to "add" the content to the variable $page_content (new Page() SESSION) $page_content is a variable that is either instantiated as a Class or is a SESSION CLass of new Page()

the class has a method "add_column_content"....however when the above code run....although a "print_r" reveals that the class object exists...but i get a
Call to undefined method stdClass::add_column_content()
what gives? as the class is being instantiated and the class is being called before the session_start()
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Which version of php do you use?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

volka wrote:Which version of php do you use?
PHP 5

y?....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It would appear that the session loaded object didn't materialize as expected -- the class wasn't loaded at the time.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

because I wanted to know if all reflection classes/methods are available for a test script. php 5.1.6+ is needed for that.

anyway, please try

Code: Select all

//print_r($page_content);

echo '<pre>', var_export(get_class($page_content), true), "</pre>\n";
echo '<pre>', var_export(get_class_methods($page_content), true), "</pre>\n";

$page_content->add_column_content($content,$column,$order= false);
what does it print?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

feyd wrote:It would appear that the session loaded object didn't materialize as expected -- the class wasn't loaded at the time.

well thats an odd statement...seeing that

Code: Select all

$page_content =  isset($_SESSION['MenuItem'])? $_SESSION['MenuItem'] : new Page(); // $_SESSION['MenuItem'] is a populated new Page()
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Volka....

i did what you suggested and i got

Code: Select all

'stdClass'

array (
)
strange...as it should have returned something right? on first load of the iframe...its content actually instantiates the session and does a "header()" to reload the said page...in order to realise that a session is created...its results is true as i get a output of the sessions variables content....

However when i try the $_GET['add_content']

this is where i get the problem....

is my reloading of the iframe.src clearing the session and restarting it?

:?: :?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if you currently have

Code: Select all

session_start();
require 'page.php'; // where the class Page is defined
change it to

Code: Select all

require 'page.php';
session_start();
The class definition muss be present before an object of that calss can be restored from the session data.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

volka wrote:The class definition muss be present before an object of that class can be restored from the session data.
yes it is...otherwise at first load it would have given me an error...

the undefined error happens when i pass a $_GET['add_content']

mind u...that how i pass the parameter is via a frame.src to which i append the url of the frame.src with the parameter...this reloads the iframe
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

kendall wrote:
volka wrote:The class definition muss be present before an object of that class can be restored from the session data.
yes it is...otherwise at first load it would have given me an error...
not necessarily.
kendall wrote:the undefined error happens when i pass a $_GET['add_content']
Yes, that is the condition for calling the object's method.


What does

Code: Select all

echo 'MenuItem: ', isset($_SESSION['MenuItem']) ? 'set':'not set', "<br />\n";
$page_content->add_column_content($content,$column,$order= false);
print?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

volka wrote: What does

Code: Select all

echo 'MenuItem: ', isset($_SESSION['MenuItem']) ? 'set':'not set', "<br />\n";
$page_content->add_column_content($content,$column,$order= false);
print?
The code

Code: Select all

if(isset($_SESSION['MenuItem'])){
print ("ok");
}else{
	print("fail");
}
prints ok...and i get the output of the session

but when i do a....

Code: Select all

if(is_a($_SESSION['MenuItem'],'Page')){ // checks if is a new Page()
print ("ok");
}else{
	print("fail");
}
it prints "fail" but i get the output of the session...its class variables
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

It's still probably:
feyd wrote:It would appear that the session loaded object didn't materialize as expected -- the class wasn't loaded at the time.
The class definition must be present when session_start() is called - each time session_start() is called.
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

volka...

thats the funny thing about it....it is other wise why am i still accessing the $_SESSION['MenuItem']'s variables? :?: :?:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

:?:
I don't understand your last post.
Post Reply