#23712 [Fbk->Opn]: DB_DataObject: fetch() fails after delete() within loop
| From: | mccarthy at ee dot ualberta dot ca | Date: | Wed, 21 May 2003 11:14:35 +0000 |
| Subject: | #23712 [Fbk->Opn]: DB_DataObject: fetch() fails after delete() within loop | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-16563@lists.php.net to get a copy of this message | ||
ID: 23712
User updated by: mccarthy at ee dot ualberta dot ca
Reported By: mccarthy at ee dot ualberta dot ca
-Status: Feedback
+Status: Open
Bug Type: PEAR related
Operating System: Linux RedHat
PHP Version: 4.3.1
Assigned To: alan_k
New Comment:
Nothing has changed:
Fatal error: Call to a member function on a non-object in
DB/DataObject.php on line 385
Again, one child is deleted and two remain.
Let me know if there is anything I can do to help.
Kind Regards,
Mike
Previous Comments:
------------------------------------------------------------------------
[2003-05-20 07:59:34] alan_k@php.net
that should have been
http://cvs.php.net/co.php/pear/DB_DataObject/DataObject.php?r=1.95
------------------------------------------------------------------------
[2003-05-20 07:58:25] alan_k@php.net
can you try the cvs version, I've just commited a fix that 'should' fix
this.
http://cvs.php.net/co.php/pear/DB_DataObject/DataObject.php?r=1.9
Regards
Alan
------------------------------------------------------------------------
[2003-05-20 05:29:53] mccarthy at ee dot ualberta dot ca
The following pieces of code fail in all of my projects:
$ca = new DataObjects_Categories;
$ca->get(<some id>);
$ca->deleteAll();
Where the class DataObjects_Categories is defined as:
class DataObjects_Categories extends DB_DataObject {
<... snip ...>
function &getSubCategories() {
$scs = new DataObjects_Sub_categories;
$scs->ca_id = $this->id;
$scs->find();
return $scs;
}
function deleteAll() {
DB_DataObject::debugLevel(1);
$sc = $this->getSubCategories();
while ($sc->fetch()) {
$sc->delete();
}
$this->delete();
DB_DataObject::debugLevel();
}
<... snip ...>
}
The script, with debugLevel(1), returns:
*--*
__find
sql QUERYSELECT * FROM sub_categories WHERE sub_categories.ca_id = 33
query DONE QUERY
__find CHECK autofetchd
__find DONE
fetchrow sub_categories DONE
sql QUERYDELETE FROM sub_categories WHERE sub_categories.id = 132
query DONE QUERY
Fatal error: Call to a member function on a non-object in
pear/lib/php/DB/DataObject.php on line 385
*--*
There were three sub_categories in the database that should have been
deleted during this execution. However, the fetch() loop only gets
executed once before the fatal error. Two sub_categories and their
parent category remain.
I believe the bug lies in the fetch() statement of:
while ($sc->fetch()) {
$sc->delete();
}
where it appears to fail after the first loop.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23712&edit=1