【发布时间】:2011-04-16 10:26:52
【问题描述】:
首先,我想确保以下是测试和克隆对象的正确方法。我正在使用 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;
现在也许我做错了,但这似乎并没有将 $html 克隆到 $test。两者都将输出“更改的标题”。
所以我的问题是,
- 我的克隆是否正确?
- 还有其他方法可以在 PHP 中克隆对象吗?
谢谢大家
【问题讨论】:
-
clone只执行浅拷贝。可能实际的 DOM 只是$html的一个属性(另一个对象)。