#23712 [NEW]: DB_DataObject: fetch() fails after delete() within loop
| From: | mccarthy at ee dot ualberta dot ca | Date: | Tue, 20 May 2003 10:29:53 +0000 |
| Subject: | #23712 [NEW]: DB_DataObject: fetch() fails after delete() within loop | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-16491@lists.php.net to get a copy of this message | ||
From: mccarthy at ee dot ualberta dot ca
Operating system: Linux RedHat
PHP version: 4.3.1
PHP Bug Type: PEAR related
Bug description: DB_DataObject: fetch() fails after delete() within loop
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 bug report at http://bugs.php.net/?id=23712&edit=1
--
Try a CVS snapshot: http://bugs.php.net/fix.php?id=23712&r=trysnapshot
Fixed in CVS: http://bugs.php.net/fix.php?id=23712&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=23712&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=23712&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=23712&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=23712&r=support
Expected behavior: http://bugs.php.net/fix.php?id=23712&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=23712&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=23712&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=23712&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23712&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=23712&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=23712&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=23712&r=gnused