note 106562 added to language.oop5.object-comparison

From: Date: Fri, 18 Nov 2011 19:36:02 +0000
Subject: note 106562 added to language.oop5.object-comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-184565@lists.php.net to get a copy of this message
It should be noted that objects can be compared using only their accessible properties using get_object_vars(). Per example, in this class: class X { public $a; private $b; public function __construct($a, $b) { $this->a = $a; $this->b = $b; } } You can ignore the private properties when comparing them outside the class scope, like this: $a = new X(1, 1); $b = new X(1, 0); var_dump(get_object_vars($a) == get_object_vars($b)); Just remember that get_object_vars() return different properties depending on the scope where you call it, so calling the above within one of X member will compare the private properties. ---- Server IP: 72.55.140.6 Probable Submitter: 66.46.85.195 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.object-comparison.php Edit -- https://master.php.net/note/edit/106562 Del: integrated -- https://master.php.net/note/delete/106562/integrated Del: useless -- https://master.php.net/note/delete/106562/useless Del: bad code -- https://master.php.net/note/delete/106562/bad+code Del: spam -- https://master.php.net/note/delete/106562/spam Del: non-english -- https://master.php.net/note/delete/106562/non-english Del: in docs -- https://master.php.net/note/delete/106562/in+docs Del: other reasons-- https://master.php.net/note/delete/106562 Reject -- https://master.php.net/note/reject/106562 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184565) next »