开发者

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,

  1. Am I cloning correctly?
  2. 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;?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜