I need to get our server running on php5 but we have an old CMS that has issu开发者_运维技巧es I need to bandaid till we have the time to have a new CMS setup and the old data (about 4000 pages with great SEO) moved.
The guts of the old CMS would load/save the page data as class variables/properties that were then serialised and saved to a file, and unserialised to be used, all by methods in the class.
$this = $ToolBox->fileUnSerialize($myFile);
You can't do that in php5 as you can not reassign the $this variable.
I could do this:
$vardata = $ToolBox->fileUnSerialize($myFile);
$this->var1 = $vardata->var1;
$this->var2 = $vardata->var2;
but there are over 50 variables. Is there a better way?
You can simply foreach over all attributes to copy them over:
$vardata = $ToolBox->fileUnSerialize($myFile);
foreach ($vardata as $_attribute => $_value) {
$this->$_attribute = $_value;
}
精彩评论