List Info

Thread: note 78488 added to function.property-exists




note 78488 added to function.property-exists
user name
2007-10-14 20:19:24
A niet way to copy properties from one object to another
avoiding stuff like:

$obj2 -> prop1 = $obj1 -> prop1;
$obj2 -> prop2 = $obj1 -> prop2;
$obj2 -> prop3 = $obj1 -> prop3;

...is this loop through all properties:

// copies all property values from obj1 to obj2
foreach ($obj1 as $prop_name => $prop_value)
{
	if (property_exists(get_class($obj2), $prop_name)) 
                 $obj2 -> {$prop_name} = $prop_value;
}
----
Server IP: 217.160.72.57
Probable Submitter: 88.70.226.170
----
Manual Page -- http://www.php.net/manual/en/function.property-exists.p
hp
Edit        -- https://master
.php.net/note/edit/78488
Del: integrated  -- h
ttps://master.php.net/note/delete/78488/integrated
Del: useless     -- http
s://master.php.net/note/delete/78488/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/78488/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/78488/spam
Del: non-english -- 
https://master.php.net/note/delete/78488/non-english
Del: in docs     -- http
s://master.php.net/note/delete/78488/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/78488
Reject      -- https://mast
er.php.net/note/reject/78488
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )