Page 1 of 1
Call to undefined method stdClass
Posted: Wed May 23, 2007 9:30 am
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()
Posted: Wed May 23, 2007 9:32 am
by volka
Which version of php do you use?
Posted: Wed May 23, 2007 9:35 am
by kendall
volka wrote:Which version of php do you use?
PHP 5
y?....
Posted: Wed May 23, 2007 9:41 am
by feyd
It would appear that the session loaded object didn't materialize as expected -- the class wasn't loaded at the time.
Posted: Wed May 23, 2007 9:42 am
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?
Posted: Wed May 23, 2007 9:45 am
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()
Posted: Wed May 23, 2007 9:52 am
by kendall
Volka....
i did what you suggested and i got
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?

Posted: Wed May 23, 2007 9:59 am
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.
Posted: Wed May 23, 2007 10:02 am
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
Posted: Wed May 23, 2007 10:15 am
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?
Posted: Tue Jul 17, 2007 3:26 pm
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
Posted: Tue Jul 17, 2007 5:11 pm
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.
Posted: Tue Jul 17, 2007 7:25 pm
by kendall
volka...
thats the funny thing about it....it is other wise why am i still accessing the $_SESSION['MenuItem']'s variables?

Posted: Tue Jul 17, 2007 7:38 pm
by volka

I don't understand your last post.