From f0cc1dbedd660c3d1e3014fe5673cfb2d77622ae Mon Sep 17 00:00:00 2001 From: icewing Date: Thu, 6 Mar 2008 14:21:44 +0000 Subject: Marcus Povey * Casting takes advantage of constructor git-svn-id: https://code.elgg.org/elgg/trunk@99 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/objects.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'engine/lib/objects.php') diff --git a/engine/lib/objects.php b/engine/lib/objects.php index 62039ff38..f939b0ce5 100644 --- a/engine/lib/objects.php +++ b/engine/lib/objects.php @@ -21,10 +21,8 @@ function row_to_elggobject($row) { if (empty($row)) return $row; - $object = new ElggObject(); - foreach(get_object_vars($row) as $property => $value) - $object->$property = $value; - return $object; + + return new ElggObject($row); } /** @@ -367,8 +365,13 @@ $this->attributes = array(); - if (!empty($id)) { - if ($object = get_object($id)) { + if (!empty($id)) { + if ($id instanceof stdClass) + $object = $id; // Create from db row + else + $object = get_object($id); + + if ($object) { $objarray = (array) $object; foreach($objarray as $key => $value) { $this->attributes[$key] = $value; -- cgit v1.2.3