| 
| Subject: | Nice overkill. | 
|---|
 | Summary: | Package rating comment | 
|---|
 | Messages: | 5 | 
|---|
 | Author: | Artur Graniszewski | 
|---|
 | Date: | 2013-04-12 11:59:31 | 
|---|
 | Update: | 2013-04-18 13:07:58 | 
|---|
 |  |  |  | 
Artur Graniszewski rated this package as follows:
| Utility: | Bad | 
|---|
| Consistency: | Good | 
|---|
| Examples: | Good | 
|---|
|  | 
  Artur Graniszewski - 2013-04-12 11:59:31Nice overkill. You reimplemented sth already done in pure PHP:
 <?php
 
 class class1
 {
 private $x;
 private $y;
 
 function __set($propiedad,$valor)
 {
 $this->$propiedad=$valor;
 }
 function __get($propiedad)
 {
 return $this->$propiedad;
 }
 }
 
 $object1=new class1();
 $object1->x=10;
 $object1->y=20;
 
 $object2=new class1();
 $object2->x=10;
 $object2->y=20;
 
 // returns true
 var_dump($object1 == $object2);
 
 $object3=new class1();
 $object3->x=10;
 $object3->y=10;
 
 // returns false
 var_dump($object1 == $object3);
 
 
  Jorge Prado - 2013-04-17 17:55:21 - In reply to message 1 from Artur GraniszewskiThat's already in PHP but you can not use var_dump to compare objects and get a result and assign it to a variable, there is not internally in PHP to compare objects because if I do this:
 if($object1 == $object3)
 echo "notequals";
 else
 echo "EQUALS";
 
 It will always show "Equals". But if you use the class you'll receive false in this case.
 
 
 
 
  Artur Graniszewski - 2013-04-18 08:49:46 - In reply to message 2 from Jorge PradoI'm afraid I don't understand you. 
PHP has already built-in functionality for comparing objects (it's been greatly improved in PHP5):
 php.net/manual/en/language.oop5.obj ...
 
If you want to assign the boolean value to the variable then do sth like this:
 
$areObjectsEqual = ($object1 == $object2); // parethesis are optional here
  Artur Graniszewski - 2013-04-18 08:54:00 - In reply to message 3 from Artur GraniszewskiBTW, you have error in your code, it should look like this:
 if($object1 == $object3)
 echo "EQUALS";
 else
 echo "not equals";
 
 (you echo'ed "not equals" in case of ==).
  Jorge Prado - 2013-04-18 13:07:58 - In reply to message 4 from Artur GraniszewskiYou are right, I was wrong. |