Jump to content

Classes over session


sgaron

Recommended Posts

I created a class that can only display in a certain div and I want to use Ajax to do the refresh function.

What I did, I added an if statement after my class that takes care of the update. The javascript part works fine but the class in php gives me the following error: The script tried to execute a method or access a preoperty of an incomplete object. Please ensure that the class definition of the object "class" you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition.

that is how my php files look like...

index.php
[code]
<?php
if (!isset($_SESSION)){
    session_start();
}
require "class.php";

echo "<head><script type=\"text/javascript\" src=\"class.js\" /></head>";

$_SESSION['class'] = new class();
$_SESSION['class']->display();

echo "<input type=button onclick='refresh('class');'>";
?>
[/code]

class.php

[code]
<?php
class class{
    class(){}

    display(){echo "<div id=class>display</div>";}

    refresh(){echo "refresh";}
}

if ($_POST['to_refresh']){
    $_SESSION[$_POST['to_refresh']]->refresh();
    return;
}
?>
[/code]

What can I do to access my object without getting that error message??
Link to comment
https://forums.phpfreaks.com/topic/33785-classes-over-session/
Share on other sites

But isnt it in the same session ?? Cause my class.js does NOT call class.php it calls index.php and index.php as the [b]if[/b] statement because of the [b]require[/b]...

I'm right now creating a framework for my future app so I want everything in the class.php and class.js to be as generic as possible. And I want to have to insert the least function and code possible in the index.php for eveything to work ..

I cant initialize the class in class.php because I'll be initializing more that one control anyway, thus why I chose to create a class.

Any Idea on what I can do to make this work ?
Link to comment
https://forums.phpfreaks.com/topic/33785-classes-over-session/#findComment-158454
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.