Get_class()期望参数1是使用bit -url-shortener时给出的object, string


get_class() expects parameter 1 to be object, string given when using bitly-url-shortener

我想使用bit -url-shortener (http://www.yiiframework.com/extension/bitly-url-shortener/)来缩短我的url。我使用的代码如下,

<?php Yii::app()->bitly->shorten('http://www.betaworks.com')->getResponseData(); ?>

它给了我这个错误,

 get_class() expects parameter 1 to be object, string given
D:'_App'buddyshop'protected'extensions'bitly'VGBitly.php(578)
566      */
567     public function getErrorMessage()
568     {
569         return $this->errorMessage;
570     }
571     
572     /**
573      * @return array - Convert a SimpleXML object to an array so we
574      * Could safely store it in the cache and retrieve it when needed.
575      */
576     protected function simplexml2array($xml) 
577     {
578         if (get_class($xml) == 'SimpleXMLElement') 
579         {
580             $attributes = $xml->attributes();
581             foreach($attributes as $k=>$v) 
582             {
583                 if ($v) $a[$k] = (string) $v;
584             }
585             $x = $xml;
586             $xml = get_object_vars($xml);
587         }
588         if (is_array($xml)) 
589         {
590             if (count($xml) == 0) return (string) $x; // for CDATA

第578行显示错误。

任何帮助都将非常感激。谢谢!

因为你已经联系了代码的作者,希望你能从他们那里得到更好的解决方案,但同时你可以在下面放置它:

替换:

if (get_class($xml) == 'SimpleXMLElement') 

if (is_object($xml) && get_class($xml) == 'SimpleXMLElement')