php“脚本试图执行方法或访问不完整对象的属性”错误

时间:2009-08-02 21:08:35

标签: php zend-framework session

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

然而,对我来说情况并非如此。

我收到以下错误:

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

知道为什么吗?

以下是三个相关文件:login.php,members.php和functions.php ...

的login.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;
  }

}

1 个答案:

答案 0 :(得分:3)

你收到这条消息:

  

请确保上课   定义   “Zend_Http_Client_Adapter_Socket”的   您正在尝试操作的对象   在unserialize()之前加载了on   被称为

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

的一个实例

因此,在session_start之前,您应该加载该类,例如,使用以下内容:

Zend_Loader::loadClass('Zend_Http_Client_Adapter_Socket');

这应解决这个问题......但是,由于Zend Framework有很多依赖于彼此的类,你可能会碰到另一个......


永远摆脱这些错误的一种方法是使用Zend Framework的自动加载器:不用自己用Zend_Loader::loadClass定位类,你可以注册/激活自动加载器,它会自动为你加载类,无论何时它们需要。

当然,在调用session_start 之前也必须这样做: - )

有关ZF自动加载器的更多信息,您可以查看this page of the manual