note 76681 added to function.get-object-vars

From: Date: Wed, 25 Jul 2007 21:21:52 +0000
Subject: note 76681 added to function.get-object-vars
Groups: php.notes 
Request: Send a blank email to php-notes+get-128930@lists.php.net to get a copy of this message
If you're looking to compare to like objects this is a way you can do it: <? function objCompare($oA, $oB) { $oVarsA=get_object_vars($oA); $oVarsB=get_object_vars($oB); if(($aKeys=array_keys($oVarsA)) !== array_keys($oVarsB)) { $GLOBALS[err]=ERR(__CLASS__,__FUNCTION__,__FILE__,'',"Supplied objects are not of same class."); return false; } else { foreach($aKeys as $sKey) { if($oVarsA[$sKey] !== $oVarsB[$sKey]) { $retAr[]=$sKey; } } return $retAr; } } $o=new Audit; $o->_load(1); $aDifferences=objCompare($o->oOldVersion, $o->oNewVersion); echo "Between the compared objects, the variables below differ from eachother:<br/>"; print_r($aDifferences); echo "<br/><br/><h2>For an automated output:</h2>"; foreach($aDifferences as $sVar) { echo "OLD VERSION of var ".$sVar.":<br/>".$o->oOldVersion->{$sVar}."<br/><br/>"; echo "NEW VERSION of var ".$sVar.":<br/>".$o->oNewVersion->{$sVar}."<br/>"; echo "<hr>"; } ?> ---- Server IP: 209.41.74.194 Probable Submitter: 134.29.231.215 ---- Manual Page -- http://www.php.net/manual/en/function.get-object-vars.php Edit -- https://master.php.net/note/edit/76681 Del: integrated -- https://master.php.net/note/delete/76681/integrated Del: useless -- https://master.php.net/note/delete/76681/useless Del: bad code -- https://master.php.net/note/delete/76681/bad+code Del: spam -- https://master.php.net/note/delete/76681/spam Del: non-english -- https://master.php.net/note/delete/76681/non-english Del: in docs -- https://master.php.net/note/delete/76681/in+docs Del: other reasons-- https://master.php.net/note/delete/76681 Reject -- https://master.php.net/note/reject/76681 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128930) next »