【问题标题】:php "script tried to execute a method or access a property of an incomplete object" errorphp“脚本试图执行方法或访问不完整对象的属性”错误
【发布时间】:2010-11-16 05:34:59
【问题描述】:

我查过这个错误,似乎常见的问题是由于没有在 session_start() 之前放置 include() 或 require()。

然而,这对我来说不是这样。

我收到以下错误:

致命错误:Zend_Http_Client::request() [zend-http-client.request]:脚本试图执行方法或访问不完整对象的属性。请确保您尝试操作的对象的类定义“Zend_Http_Client_Adapter_Socket”已加载 unserialize() 被调用或提供 __autoload() 函数以在 /home/content 中加载类定义///*/*****/html/ZendGdata-1.8.4PL1/library/Zend/Http/Client.php 865行

知道为什么吗?

这里是三个相关文件:login.php、members.php和functions.php...

登录.php:

 $newIncludePath = array();
 $newIncludePath[] = '../ZendGdata-1.8.4PL1/library';
 $newIncludePath = implode($newIncludePath);
 set_include_path($newIncludePath);

 // load classes
 require_once 'Zend/Loader.php';
 Zend_Loader::loadClass('Zend_Gdata');
 Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
 Zend_Loader::loadClass('Zend_Gdata_Calendar');
 Zend_Loader::loadClass('Zend_Http_Client');
 Zend_Loader::loadClass('Zend_Gdata_AuthSub');

 session_start();


 $serviceName = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name ('cl') for calendar
 $applicationName = 'yourCompany-yourAppName-v1';

 // Create an authenticated HTTP client
 $httpClient = Zend_Gdata_ClientLogin::getHttpClient('*****@gmail.com', '*****', $serviceName, null, $applicationName);
 $client = new Zend_Gdata_Calendar($httpClient, $applicationName); // Create an instance of the Calendar service

 $_SESSION['gdataCal'] = $client;

members.php:

 $newIncludePath = array();
 $newIncludePath[] = '../ZendGdata-1.8.4PL1/library';
 $newIncludePath = implode($newIncludePath);
 set_include_path($newIncludePath);

 // load classes
 require_once 'Zend/Loader.php';
 Zend_Loader::loadClass('Zend_Gdata');
 Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
 Zend_Loader::loadClass('Zend_Gdata_Calendar');
 Zend_Loader::loadClass('Zend_Http_Client');
 Zend_Loader::loadClass('Zend_Gdata_AuthSub');

 session_start();

 $g_url = add_gcal($_SESSION['gdataCal'], $_SESSION['title'].....etc.);

functions.php:

 <?php

 $newIncludePath = array();
 $newIncludePath[] = '../ZendGdata-1.8.4PL1/library';
 $newIncludePath = implode($newIncludePath);
 set_include_path($newIncludePath);

 // load classes
 require_once 'Zend/Loader.php';
 Zend_Loader::loadClass('Zend_Gdata');
 Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
 Zend_Loader::loadClass('Zend_Gdata_Calendar');
 Zend_Loader::loadClass('Zend_Http_Client');

session_start();

function add_gcal($gdataCal, $title....etc.){

try {

    $newEvent = $gdataCal->newEventEntry();

    $newEvent->title = $gdataCal->newTitle($title);
    $newEvent->where = array($gdataCal->newWhere($where));
    $newEvent->content = $gdataCal->newContent("$desc");

    $when = $gdataCal->newWhen();
    $when->startTime = $date;
    $when->endTime = $date; 
    $newEvent->when = array($when);

    $createdEvent = $gdataCal->insertEvent($newEvent);
    return $createdEvent->id->text;

  } catch (Zend_Gdata_App_Exception $e) {
        return NULL;
  }

}

【问题讨论】:

    标签: php zend-framework session


    【解决方案1】:

    您收到此消息:

    请确保类 定义 “Zend_Http_Client_Adapter_Socket”的 您尝试操作的对象 on 在 unserialize() 之前加载 被调用

    所以,我想你在会话中有一些东西(这意味着以序列化的形式存储)是 Zend_Http_Client_Adapter_Socket 的一个实例

    因此,在session_start 之前,您应该加载该类,例如,使用类似这样的东西:

    Zend_Loader::loadClass('Zend_Http_Client_Adapter_Socket');
    

    这应该可以解决这个问题...但是,由于 Zend Framework 有很多相互依赖的类,您可能会遇到另一个...


    永远摆脱这些错误的一种方法是使用 Zend Framework 的自动加载器:与其使用 Zend_Loader::loadClass 自己定位类​​,您只需注册/激活自动加载器,它会在需要时自动为您加载类.

    当然,这也必须在致电session_start 之前完成:-)

    有关采埃孚自动装弹机的更多信息,您可以查看this page of the manual

    【讨论】:

    • 我发现即使在加载类之前更改$_SESSION(没有显式调用session_start())也会导致这种行为。
    猜你喜欢
    • 2012-02-02
    • 2014-01-06
    • 1970-01-01
    • 2017-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-20
    • 1970-01-01
    相关资源
    最近更新 更多