ID: 9477 Updated by: jmoore Reported By: [EMAIL PROTECTED] Status: Open Old-Bug Type: Scripting Engine problem Bug Type: Documentation problem PHP Version: 4.0.4pl1 Assigned To: Comments: Docu problem not script engine problem. - James Previous Comments: --------------------------------------------------------------------------- [2001-03-09 01:54:31] [EMAIL PROTECTED] Ok. This is absolutely amazing. I went to the archives. There are a good number of people all wondering about the same issue. Why is =&new required when every other language semantically understands that new is an operator and =new is not an assignment but rather implicit construction of an object? Any takers? --------------------------------------------------------------------------- [2001-03-09 01:28:37] [EMAIL PROTECTED] this all makes sense and generally you do NOT need to use "=& new" your case included, this is due to PHPs nature and this all has been discussed search the archives (marc.theaimsgroup.com) for "reference counting" and "this+constructor" or maybe "=&" to understand when it required to use "=&" with new there are some resources on reference counting in the manual or at zend.com IRC --------------------------------------------------------------------------- [2001-03-09 00:32:08] [EMAIL PROTECTED] I retract this bug. I think the issue is that I was looking for pointer semantics in a language that does not support it but at the same time is not strongly typed so that what appears to be correct, does not in fact reset the reference but actually overwrites the original object by assignment. Thank you all for your help. I now have a proper reference implementation of the subscriber/publisher pattern for PHP. Hopefully, I'll be able to keep this all straight for any other patterns I conver to PHP. Just out of curiosity, has ANYONE questioned the whole =& new construct's necessity in terms of why the semantics allows for = new as well??? When would you want to assign the a copy of the object you just created? Any help would be appreciated. --------------------------------------------------------------------------- [2001-03-08 20:55:49] [EMAIL PROTECTED] bogusifying apparently you do not know what you are doing here exactly, please read "references explained" from the manual again... /* your version - you do not destroy the reference, you simply overwritte all referenced variables (remember they are all ONE variable know) with "" */ function junk($name){$this->array[$name]="";} /* corrected version - this one does what it is written in your description */ function junk($name){unset($this->array[$name]);} the corrected one works for me. /* to clear things up a bit - the following code does the following: remove the reference by replacing it with another (to $t), I could imagine you thought it does something different */ function nojunk($name){$t="";$this->array[$name]=&$t;} please note I still did not read your comments, your code reduced code was enough to understand the situation completely note: please do not use pass-by-ref in call time --------------------------------------------------------------------------- [2001-03-08 20:07:23] [EMAIL PROTECTED] I'm really getting tired of this. I guess what I REALLY needed to do is strip out the do nothing functions in the skeletons I had on that page because even though they were base classes, everyone was missing the point. Here is the simplest case that generates an error. Anyone want to take a stab at why it happens? <?php class obj { var $array; // Assigns object reference to the associative array function test($name,$obj){$this->array[$name]=&$obj;} // Removes the reference from the associative, supposedly // but what it does decrease the actual object to nothing function junk($name){$this->array[$name]="";} // If I do it this way it works. The object isn't nuked. // What gives? Do I *HAVE* to use =&$ when assigning refs? // Is there an array function that can be used to simply // remove the array element out, w/o expensive copying? function nojunk($name){$t="";$this->array[$name]=&$t;} }; // Our do nothing class. class me{ function test(){echo "Hello, I'm still validn";} }; // Please don't tell me not to send the reference to the // object because I need to have only one copy of the object // and not a million of them especially since these objects // might be opening files and sockets. $m=& new me(); $o=& new obj(); // This section works $o->test("test",&$m); $m->test(); $o->nojunk("test"); $m->test(); // This section fails.... $o->test("test",&$m); $m->test(); $o->junk("test"); // Right here $m->test(); ?> So? What's the deal? Once you assign a reference to a variable, you're done? You can't ever reassign the reference? Does what I'm proposing make sense syntactically speaking? I want the array to contain the reference to the object, but then I want to be able to unassign the reference from the array so that that particular object doesn't get used. An unregistration as it were. --------------------------------------------------------------------------- The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online. ATTENTION! Do NOT reply to this email! To reply, use the web interface found at http://bugs.php.net/?id=9477&edit=2 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]