Php 为什么输出为空?
我知道我一定是做错了什么。当我这样做时:Php 为什么输出为空?,php,zend-framework,gdata,Php,Zend Framework,Gdata,我知道我一定是做错了什么。当我这样做时: echo '<pre>'; print_r($event->when); echo '</pre>'; Zend_Gdata_App_Extension_Published Object ( [_rootElement:protected] => published [_rootNamespace:protected] => atom [_rootNamespaceURI:protected] =>
echo '<pre>';
print_r($event->when);
echo '</pre>';
Zend_Gdata_App_Extension_Published Object
(
[_rootElement:protected] => published
[_rootNamespace:protected] => atom
[_rootNamespaceURI:protected] =>
[_extensionElements:protected] => Array
(
)
[_extensionAttributes:protected] => Array
(
)
[_text:protected] => 2011-06-15T03:32:14.000Z
[_namespaces:protected] => Array
(
[atom] => Array
(
[1] => Array
(
[0] => http://www.w3.org/2005/Atom
)
)
[app] => Array
(
[1] => Array
(
[0] => http://purl.org/atom/app#
)
[2] => Array
(
[0] => http://www.w3.org/2007/app
)
)
)
)
然后,我尝试通过执行以下操作来获得startTime
:
pr($event->published);
但我什么也没得到
然而,当我这样做的时候:
echo '<pre>';
print_r($event->when);
echo '</pre>';
Zend_Gdata_App_Extension_Published Object
(
[_rootElement:protected] => published
[_rootNamespace:protected] => atom
[_rootNamespaceURI:protected] =>
[_extensionElements:protected] => Array
(
)
[_extensionAttributes:protected] => Array
(
)
[_text:protected] => 2011-06-15T03:32:14.000Z
[_namespaces:protected] => Array
(
[atom] => Array
(
[1] => Array
(
[0] => http://www.w3.org/2005/Atom
)
)
[app] => Array
(
[1] => Array
(
[0] => http://purl.org/atom/app#
)
[2] => Array
(
[0] => http://www.w3.org/2007/app
)
)
)
)
我明白了:
$StartTime = $event->when->startTime;
$dateAdded = $event->published->text;
echo $dateAdded;
我可以做到:
我看到一个输出…
startTime
被标记为受保护。你不能像以前那样从外面引用它。该对象中必须有一个getter函数“getStartTime()”函数,允许您公开引用它
编辑:它还返回一个对象数组,而不是一个单独的对象,因此您需要像以下那样引用它:
$event[0]->getterFunction()
或使用foreach
在数组中循环访问循环中的各个对象startTime
标记为受保护。你不能像以前那样从外面引用它。该对象中必须有一个getter函数“getStartTime()”函数,允许您公开引用它
编辑:它还返回一个对象数组,而不是一个单独的对象,因此您需要像这样引用它:$event[0]->getterFunction()
或使用foreach
访问循环中的单个对象,根据,有一个名为getStartTime()的方法
这会给你时间
如果执行$event->when[0]->getStartTime()
或$event->when[0]->startTime
,您将获得开始时间。根据,有一个名为getStartTime()
的方法将为您提供时间
如果执行
$event->when[0]->getStartTime()
或$event->when[0]->startTime
,您将获得开始时间。情况似乎并非如此。例如,我可以访问pr($event->published);即使数组显示[\u rootElement:protected]=>published,我仍然可以执行$dateAdded=$event->published->text;然后echo$dateAdded并查看结果。因此,引用受保护的变量应该神奇地调用getter方法。请尝试echo$event[0]->startTime
(您应该引用数组元素,因为它看起来像是返回了一个事件对象数组)。我想应该行得通,但事实似乎并非如此。例如,我可以访问pr($event->published);即使数组显示[\u rootElement:protected]=>published,我仍然可以执行$dateAdded=$event->published->text;然后echo$dateAdded并查看结果。因此,引用受保护的变量应该神奇地调用getter方法。请尝试echo$event[0]->startTime
(您应该引用数组元素,因为它看起来像是返回了一个事件对象数组)。我想应该行得通。是的-我大约6小时前就试过了。。。致命错误:调用未定义的方法Zend\u Gdata\u Calendar\u EventEntry::getStartTime()致命错误:调用非对象上的成员函数getStartTime(),再次更新。。。我阅读了更多内容,并查看了您在上面发布的代码,以及何时是一个数组,这解释了我前面的示例无法工作的原因。尝试$event->when[0]->getStartTime()
或者甚至$event->when[0]->startTime
。终于成功了!谢谢你们两个弄明白了这一点。我对这件事一直很生气!是的-我6小时前就试过了。。。致命错误:调用未定义的方法Zend\u Gdata\u Calendar\u EventEntry::getStartTime()致命错误:调用非对象上的成员函数getStartTime(),再次更新。。。我阅读了更多内容,并查看了您在上面发布的代码,以及何时是一个数组,这解释了我前面的示例无法工作的原因。尝试$event->when[0]->getStartTime()
或者甚至$event->when[0]->startTime
。终于成功了!谢谢你们两个弄明白了这一点。我对这件事一直很生气!