note 128273 added to language.oop5.object-comparison
| From: | cpmjr1 at gmail dot com | Date: | Thu, 02 Mar 2023 17:32:19 +0000 |
| Subject: | note 128273 added to language.oop5.object-comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220230@lists.php.net to get a copy of this message | ||
It is not immediately obvious based on the docs, but the equality comparison operator does also
check protected and private properties.
Example:
<?php
class A { public $a = 0; private $b = 1; public function __construct($test) {$this->b = $test;}}
echo "A(1) == A(2) " . var_export((new A(1)) == (new A(2)), true) . "\n";
echo "A(1) == A(1) " . var_export((new A(1)) == (new A(1)), true) . "\n";
?>
Output:
A(1) == A(2) false
A(1) == A(1) true
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 169.47.119.36)
----
Manual Page -- https://php.net/manual/en/language.oop5.object-comparison.php
Edit -- https://main.php.net/note/edit/128273
Del: integrated -- https://main.php.net/note/delete/128273/integrated
Del: useless -- https://main.php.net/note/delete/128273/useless
Del: bad code -- https://main.php.net/note/delete/128273/bad+code
Del: spam -- https://main.php.net/note/delete/128273/spam
Del: non-english -- https://main.php.net/note/delete/128273/non-english
Del: in docs -- https://main.php.net/note/delete/128273/in+docs
Del: other reasons-- https://main.php.net/note/delete/128273
Reject -- https://main.php.net/note/reject/128273
Search -- https://main.php.net/manage/user-notes.php