Put back Yii::getObjectVars() and fixed infinite loop in Object::toArray().

This commit is contained in:
Qiang Xue
2013-06-14 17:23:37 -04:00
parent b184a75d68
commit d4910ee4f5
2 changed files with 14 additions and 3 deletions

View File

@@ -624,6 +624,19 @@ class YiiBase
$object->$name = $value;
}
}
/**
* Returns the public member variables of an object.
* This method is provided such that we can get the public member variables of an object.
* It is different from "get_object_vars()" because the latter will return private
* and protected variables if it is called within the object itself.
* @param object $object the object to be handled
* @return array the public member variables of the object
*/
public static function getObjectVars($object)
{
return get_object_vars($object);
}
}
YiiBase::$aliases = array(

View File

@@ -8,7 +8,6 @@
namespace yii\base;
use Yii;
use yii\helpers\ArrayHelper;
/**
* @include @yii/base/Object.md
@@ -223,11 +222,10 @@ class Object implements Arrayable
/**
* Converts the object into an array.
* The default implementation will return all public property values as an array.
* However, if the object is traversable, it will return the data obtained by the data iteration.
* @return array the array representation of the object
*/
public function toArray()
{
return ArrayHelper::toArray($this, false);
return Yii::getObjectVars($this);
}
}