Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.