Doc #36971 [Com]: unset() no longer works on $this in PHP5

From: Date: Mon, 14 Jan 2013 21:53:42 +0000
Subject: Doc #36971 [Com]: unset() no longer works on $this in PHP5
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-9403@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=36971&edit=1 ID: 36971 Comment by: hujuice at inservibile dot org Reported by: k at phpkoala dot com Summary: unset() no longer works on $this in PHP5 Status: Closed Type: Documentation Problem Package: Documentation problem Operating System: Linux PHP Version: 5.1.2 Block user comment: N Private report: N New Comment: A very old problem. I'm managing exactly a scenario like the one told by scott in 2007-07-18 13:53 UTC My objects MUST match with database rows, via object methods. $myObj->load($id); // SELECT $myObj->save(); // INSERT/UPDATE $myObj->delete(); // DELETE But when I call the delete() function my objects lose their sense. I feel that the original requirement is not so strange. I understand that changing type is quite absurd, but now I need to introduce checks to establish if the object is still alive. A native solution could be appreciated. Regards, HUjuice Previous Comments: ------------------------------------------------------------------------ [2011-09-20 15:48:36] james at esilogix dot com I have an object Criteria. It has a method apply(). I would like to pass an object to apply() by reference, and if it does not satisfy the criteria, I would like Criteria->apply() to be able to destroy the object. I've tried unset, I've tried object->destroy() with "unset($this)", doesn't work. I can set it to null, but then I have a null object in my collection, and I don't want that. ------------------------------------------------------------------------ [2007-08-20 12:11:42] vrana@php.net This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "It is not possible to unset $this inside an object method since PHP 5." ------------------------------------------------------------------------ [2007-07-18 13:53:56] scott at utnow dot com This is really quite simple to understand folks... The guy has a class that is sitting there doing it's thing. He has a function (say it's 'DestroyMe') that should do simply that. The best case I can imagine... The class is 'object' and it interfaces with a row in a table in a database. If you're going to delete the object's row from the table, it probably makes sense to destroy the class handling it. function destroy() { delete row; destruct class; } Thus it would be helpful to be able to do what he's asking. Now whether it fits within the realm of responsible coding or not I'm not the judge... lol ------------------------------------------------------------------------ [2007-04-07 01:10:43] edwardzyang at thewritingpot dot com It's tough to understand what your problem is without more code. If you are doing: for ($i = 0; $i < 1000000; $i++) { $obj = new Foo(); // do stuff with $obj unset($obj); } That should be sufficient. Could you be more specific? Usually, if the PHP interpreter is running out of memory, you've got some bad code that needs refactoring. ------------------------------------------------------------------------ [2007-04-06 20:41:05] joel at propbot dot com The problem comes into mind when your creating an object and going through a loop. The script just grows and grows until your out of memory. We are creating an object doing what we need to do with it and trying to destroy it. Anybody have a solution? I really don't want to have to go through every variable inside the object and do an unset(). ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=36971 -- Edit this bug report at https://bugs.php.net/bug.php?id=36971&edit=1

« previous php.doc.bugs (#9403) next »