Re: adding objects with + equal to array process

From: Date: Wed, 05 Jul 2000 13:16:31 +0000
Subject: Re: adding objects with + equal to array process
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-23568@lists.php.net to get a copy of this message
waldschrott wrote: > 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'; If you are treating objects like arrays, you probably should have used arrays in the first place. Usually, an object is a C struct with a predefined set of slots, plus a set of functions operating on that struct. In PHP, objects are different in the way that their set of slots is not predefined, which makes them more hashlike than structlike. This is nice, but it does not always help to clear up the situation: If you are using objects as hashes, you should have been using arrays/hashes in the first place. That would enable you to use all PHP array functions on them, which you cannot do with objects. if you are using object as objects, that is, as a predefined structure associated with a set of functions manipulating that structure, you should have defined your class as class A { var $someary = array(); // my array function manipulate_array() { ... } } $a = new A; $a2 = new A; and then use $a->someary[index] instead of $a->index. That would enable you to use all PHP array functions on $a->somary and $a2->someary without problems. It is not necessary to change to language at all, except perhaps for a php.ini switch will issue warnings if you add slots to an object at runtime (you treat objects like hashes) and wbhich should be enabled by default. Also, what is the semantic of $a = new A; $b = new B; $c = $a + $b; What is the type and class of $c? What instance functions are available to $c? Kristian -- Kristian Köhntopp, NetUSE AG Siemenswall, D-24107 Kiel Tel: +49 431 386 436 00, Fax: +49 431 386 435 99 Using PHP3? See our web development library at http://phplib.netuse.de/

« previous php.dev (#23568) next »