Re: adding objects with + equal to array process
| From: | jalal | Date: | Wed, 05 Jul 2000 11:12:23 +0000 |
| Subject: | Re: adding objects with + equal to array process | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-23550@lists.php.net to get a copy of this message | ||
Hi waldschrott
This depends on the fact that the data in an object is public. Which it
is...
I would have two objections
1. Some day it would be real nice if we could make class data
'private', in which case this style of code would break.
2. I think it is good practise to consider the data in a class as
private, even if it is not in reality. Changes to the state of an
object should go through the proper methods. I'm not comfortable with
code that can change my objects in unpredictable ways...
I suggest creating a function, somewhat along the lines of Java, such
that:
$obj1 = new Schrott;
$obj2 = new Schrott;
add_schrotts( $obj1, $obj2 );
Besides, I always hated operator overloading...
jalal
On Wed, 05 Jul 2000 12:12:12 +0200, waldschrott wrote:
>Hi there,
>it s possible to glue two arrays with the operator "+", eg.
>$array1=array('arr','arr2'); $array2=array('arr3');
>$array3=$array1+$array2; // $array3==array('arr','arr2','arr3');
>
>I think that would be useful with objects too.
>$obj->property='a'; $obj2->property2='b'; $resobj=$obj+$obj2;
>$resobj should then contain these properties
>$obj->property=='a' && $obj->property2=='b';
>
>It s very annoying to do this by hand and it shouldn t be very
>performant operating on larger objects.
>
>regards
>
>
>--
>PHP Development Mailing List <http://www.php.net/>
>To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
>For additional commands, e-mail: php-dev-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net