带有不完整对象的PHP会话 [英] PHP Session with an Incomplete Object

查看:68
本文介绍了带有不完整对象的PHP会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个错误,我不知道如何解决,所以我想知道是否可以得到一些帮助.

I'm getting an error I don't know how to fix so I wondering if I could get some help.

这是错误

Fatal error: process_form() [<a href='function.process-form'>function.process-form</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition &quot;Template&quot; of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition in /home/twinmeddev/html/template_add.php on line 44

我在process_form()函数中收到此错误.所以我得到的是,它以为我没有为模板加载类.实际上,我在顶部做到了这一点.包括'inc/item.class.php';我是否必须将其重新包含在功能中?

I get this error in the process_form() function. So what I get out of this is that, its thinking I didn't load the class for the template. Which in fact I did up at the top. The include 'inc/item.class.php'; Do I have to re-include it in the function?

这是带有错误的特定页面的代码.您可以看到我拥有应有的一切.我在哪里弄错了?

Here's the code for the particular page with the error. You can see I have everything included like it should be. Where have I gone wrong?

<?php
include 'inc/prep.php';
include 'inc/header.class.php';
include 'inc/item.class.php';
include 'inc/template.class.php';
include 'inc/formhelper.class.php';
include 'inc/formvalidator.class.php';
include_once( 'inc/config/config.php' ) ;
include_once( 'inc/DBE.class.php' ) ;
include_once( 'inc/GenFuncs.php' ) ;
include_once( 'inc/Search.class.php' ) ;

session_start();    

//Verify that user is logged in.
VerifyLogin($_SERVER['PHP_SELF'] . "?" . $_SERVER['QUERY_STRING']);

if(array_key_exists('_submit',$_POST)) {
    if($fv_errors = validate_form()) {
        show_form($fv_errors);
    } else {
        process_form();
    }
}
else {
    // The form wasn't submitted or preview was selected, so display
    show_form();
}

function validate_form(){
}

function process_form(){
    global $mysqli;

    echo var_dump($_SESSION);

    $Template = $_SESSION['template'];
    $Template->name = $_POST['name'];
    $Template->descript = $_POST['descript'];
    $Template->user = $_SESSION['User'];
    $Template->customer = $_SESSION['CustID'];
    $Template->status = $_POST['status'];
    $Template->insert();

    //header("Location: template.php");
}

推荐答案

它缺少模板类的序列化/反序列化.

It's missing the serialize/unserialize of your template class.

在这里查看一个工作示例我在您的另一个问题上给出了

Take a look here for an working example I gave on another question of yours.

例如,您可能想要这样:

For instance, you probably want this:

<?php
  $_SESSION['template'] = serialize($template);
?>

<?php
  $template = unserialize($_SESSION['template']);
?>

阅读有关将其移至顶部的评论可提供一个提示.

reading your comment about moving it to the top gives one hint.

当您调用session_start()时,会发生自动序列化/反序列化. 这意味着包含文件并调用session_start()的顺序非常重要.

The automatic serialization/unserialization occurs when you call session_start().
That means the order in which you include your files and call the session_start() is very important.

例如:

这是错误的:

<?php
session_start();
include 'inc/template.class.php';
?>

这是正确的:

<?php
include 'inc/template.class.php';
session_start();
?>

现在,我在您的示例中看到它的顺序正确,但是我还注意到您在包含template.class.php

Now, I see in your example that it is in the CORRECT order, but I also notice you do many other includes before including template.class.php

是否可能其中一个包含项(也许是prep.php或header.class.php)也调用了start_session()?
如果是,那就是您的问题(session_start()在template.class.php之前被调用).

Would it be possible that one of those includes (perhaps prep.php or header.class.php) does call start_session() too?
If yes, that was your issue (session_start() being called before your template.class.php).

这篇关于带有不完整对象的PHP会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆