₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,329,250 members, 8,439,518 topics. Date: Sunday, 05 July 2026 at 12:31 PM

Toggle theme

Tracking Changes In PHP Properties - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingTracking Changes In PHP Properties (855 Views)

1 Reply (Go Down)

Tracking Changes In PHP Properties by Nobody: 9:17am On May 27, 2013
Hi guys, i got a request to create a script that sends mail of a member anytime there's a new change in Profile, so that the mail will send the new changes, so here is my take on it, wanted to know if this solution is optimal in terms of Memory consumption and design.

1. Collect all the Profile Data and Store in a Class and serialize and store in Db.
2. Then When next user changes his data, check to see if an old class serialized exists,
3. If it does then pull from database and (Reflection API)Scan the properties and some array of Images which will be retrieved from WordPress
4. Store the new files in New Changes not in Old changes into an addition array, then store the Old data not in New data in removed array.
5.Then update the serialize object to the recent one

and it goes on and on. Now my question is does PHP iterate over all properties including StdClass or just my class, because in Java and C#, all Objects inherit from (Java.util.Object and whatever's C# inherits from). it will be a mess scanning all properties.
Re: Tracking Changes In PHP Properties by Nobody: 11:21am On May 27, 2013

/**
* @author Okeowo Aderemi
* @version 0.1
* A class that takes an Object and checks for the Differences
* */
class MemberChanges{
private $OldObject;
private $NewObject;
public $reflectOldMember,$reflectNewMember;

public function __construct(StyljunkiMember $obj1, StyljunkiMember $obj2){
$this->OldObject=$obj1;
$this->NewObject=$obj2;
$reflectNewMember=new ReflectionObject($this->NewObject);
$reflectOldMember=new ReflectionObject($this->OldObject);
$this->reflectNewMember=$reflectNewMember;
$this->reflectOldMember=$reflectOldMember;


}
/**
* Compares the Two Object and Value and returns the Data
* @return Array The Result (addition,removed)
* */
public function compare(){
//Iterate over all properties
$result=array();
try{
//Using the Old Data get the

$ArrayOfReflectionProperty=$this->reflectNewMember->getProperties();

foreach ($ArrayOfReflectionProperty as $properties) {
//compare if new changes in code in both
$name=$properties->getName();

//exists in the New Object
$property_old_member=$this->reflectOldMember->getProperty($name);
//compare the two value
//Set it accessible
$property_old_member->setAccessible(true);
$properties->setAccessible(true);

if($properties->getValue($this->NewObject) === $property_old_member->getValue($this->OldObject)):
continue; // no point
else:
$result[]=array("{$properties->getName()}"=>"{$properties->getValue($this->NewObject)}" );

endif;

}
var_dump($result);
return $result;
}
catch(ReflectionException $e){
fwrite(STDOUT,sprintf("Reflection Exception:[%s]",$e->getMessage()));
}
}




}
Re: Tracking Changes In PHP Properties by Nobody: 11:27am On May 27, 2013
It works now for properties, now for methods will have to reflect each method and get return value and check the return type and compare with each other if they are of the same data type and not resources.

Re: Tracking Changes In PHP Properties by Nobody: 11:29am On May 27, 2013
NOTE: It doesn't check variable_type so its a bit error prone. obviously "12" !== 12 will return false. will update laster
1 Reply

Online Shopping System In Php Documentation HelpRunning Python Codes In PhpHow To Create A Shipping Tracking On Website.?234

Respondents To Agile Software Development Survey Wanted For Research Purposes.How To Programme A PBXI Need Best Ebook For Java