|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2001-02-27 08:57 UTC] passionplay at hotmail dot com
standard php rpm 4.04p1 from rpmfind.net Scripts are clearly marked and available in source format as well as showing necessary details at this URL. http://www.poetryunlimited.com/test This bug will create significant problems when dealing with object references as needed in advanced patterns (GoF 1994). Hope you guys can figure it out. I would hate to have to have extra objects kicking around just because of whatever. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 15:00:02 2025 UTC |
> Did I miss anything in helping debug this issue or did I > just do too much? you did the wrong thing! the following passage is the only one I have read, I have not visited your site, nor anything else (we simply do not have the time to do this kind of things, it's exactly the same in any bigger OS project I know of (eg. bugzilla, provide minimized testcases or your bug will never be fixed) <quote> Bottom line: global object passed as a reference to a method and then assigned to an array which is a member of another object. The second object is then requested to delete the reference to global object. At the moment the reference in the array is deleted, the global object goes kaboom too. </quote> what I have done then, is creating PHP source reading the words above: function foo (&$foo) { $zoo->array['foo']=&$foo; unset($zoo->array['foo']); // simplified } $foo->test=TRUE; foo($foo); var_dump($foo); *** This is works for me and this is how we expect code snipplets, feel free to modify it to match exactly your problem...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 valid\n";} }; // 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.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