note 78488 added to function.property-exists
| From: | caistatcaistdotcom at osu1 dot php dot net | Date: | Mon, 15 Oct 2007 01:19:24 +0000 |
| Subject: | note 78488 added to function.property-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-131385@lists.php.net to get a copy of this message | ||
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.php
Edit -- https://master.php.net/note/edit/78488
Del: integrated -- https://master.php.net/note/delete/78488/integrated
Del: useless -- https://master.php.net/note/delete/78488/useless
Del: bad code -- https://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 -- https://master.php.net/note/delete/78488/in+docs
Del: other reasons-- https://master.php.net/note/delete/78488
Reject -- https://master.php.net/note/reject/78488
Search -- https://master.php.net/manage/user-notes.php