#23712 [Asn->Fbk]: DB_DataObject: fetch() fails after delete() within loop
| From: | alan_k@php.net | Date: | Tue, 20 May 2003 12:58:26 +0000 |
| Subject: | #23712 [Asn->Fbk]: DB_DataObject: fetch() fails after delete() within loop | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-16504@lists.php.net to get a copy of this message | ||
ID: 23712
Updated by: alan_k@php.net
Reported By: mccarthy at ee dot ualberta dot ca
-Status: Assigned
+Status: Feedback
Bug Type: PEAR related
Operating System: Linux RedHat
PHP Version: 4.3.1
Assigned To: alan_k
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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