PHP:使用==和比较对象===
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP:使用==和比较对象===相关的知识,希望对你有一定的参考价值。
Here are a few examples that show how the relationship between objects and references
<?php class Box{ public $name = "box"; } $box = new Box(); $box_reference = $box; $box_clone = clone $box; $box_changed = clone $box; $box_changed->name = "changed box"; $another_box = new Box(); // Attributes are pretty much the same echo $box == $box_reference ? 'true' : 'false'; echo "<br />"; echo $box == $box_clone ? 'true' : 'false'; echo "<br />"; echo $box == $box_changed ? 'true' : 'false'; echo "<br />"; echo $box == $another_box ? 'true' : 'false'; echo "<br />"; echo "<br />"; // Checks to see if they reference the same object echo $box === $box_reference ? 'true' : 'false'; echo "<br />"; echo $box === $box_clone ? 'true' : 'false'; echo "<br />"; echo $box === $box_changed ? 'true' : 'false'; echo "<br />"; echo $box === $another_box ? 'true' : 'false'; echo "<br />"; ?>
以上是关于PHP:使用==和比较对象===的主要内容,如果未能解决你的问题,请参考以下文章
使用 NodeJS 和 JSDOM/jQuery 从代码片段构建 PHP 页面