Can't clone an object in php simple dom parser
First things first, I'd like to make sure the below is the right way to test and clone an object. I'm using the PHP Simple HTML DOM Parser.
$page = 'www.google.ca';
$html = file_get_html($page);
$test = clone $html;
$test->find('title',0)->innertext = 'changed title';
echo $html->find('title',0)->innertext;
echo $test->find('title',0)->innertext;
Now maybe I'm doing it wrong, but this开发者_如何学Python doesn't seem to clone $html to $test. Both will output 'changed title'.
So my question(s) is,
- Am I cloning correctly?
- Is there another way of cloning an object in PHP?
Thanks guys
The documantation says so:
When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties. Any properties that are references to other variables, will remain references.
So maybe .innertext refers to another object, and it's a reference.
Have you tried $test = $html;
?
精彩评论