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

查看:26
本文介绍了带有不完整对象的 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天全站免登陆