note 114407 added to language.oop5.object-comparison
| From: | nhuhoai | Date: | Mon, 17 Feb 2014 00:45:39 +0000 |
| Subject: | note 114407 added to language.oop5.object-comparison | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-198532@lists.php.net to get a copy of this message | ||
For comparison about two objects in a class, you can use an interface like this and customize your
functions for each class:
<?php
interface EQU {
public static function compare( EQU $me, EQU $you );
public function equals( EQU $you );
}
?>
If you gotcha a super class, you can make generic functions (not safe but work with not complex
class):
<?php
abstract class SuperClass {
public function __construct( ) {
// do what you need
}
public static function compare( $obj1, $obj2 ) {
return serialize( $obj1 ) == serialize( $obj2 );
}
public function equals( $obj ) {
return static::compare( $this, $obj );
}
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/language.oop5.object-comparison.php
Edit -- https://master.php.net/note/edit/114407
Del: integrated -- https://master.php.net/note/delete/114407/integrated
Del: useless -- https://master.php.net/note/delete/114407/useless
Del: bad code -- https://master.php.net/note/delete/114407/bad+code
Del: spam -- https://master.php.net/note/delete/114407/spam
Del: non-english -- https://master.php.net/note/delete/114407/non-english
Del: in docs -- https://master.php.net/note/delete/114407/in+docs
Del: other reasons-- https://master.php.net/note/delete/114407
Reject -- https://master.php.net/note/reject/114407
Search -- https://master.php.net/manage/user-notes.php