overload() problem

This is a discussion on overload() problem within the PHP General forums, part of the PHP Programming Forums category; I'm trying to write a class for abstracting some aspects of database programming and am running into a problem: ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-22-2003
Cliff Wells
 
Posts: n/a
Default overload() problem

I'm trying to write a class for abstracting some aspects
of database programming and am running into a problem:

http://hashphp.org/pastebin.php?pid=567

The code works fine for the first instantiation of the DbTable (Product)
class,
but not the second. It seems clear that the reason it works the first
time is that overload() isn't called until after describe() in DbTable's
constructor,
so DbTable can "see" its actual properties. The second time it's
instantiated, the
class is already overloaded, so it can't and describe() fails to
populate the columns
array. Unfortunately, seeing the problem is not helping me see the
solution =P

Does anyone have an idea for a workaround for this?

BTW, the DbTable class isn't tied to any particular table, so it should
be easy to test against
any spare PostgreSQL tables you might have lying around (just change the
test code).


TIA,
Cliff
Reply With Quote
  #2 (permalink)  
Old 12-22-2003
Cliff Wells
 
Posts: n/a
Default Re: [PHP] overload() problem

Cliff Wells wrote:

> I'm trying to write a class for abstracting some aspects
> of database programming and am running into a problem:
>
> http://hashphp.org/pastebin.php?pid=567



Well, I kept hacking at it and changing the describe() method from this:


// get a description of a table
function describe($table)
{
$db = $this->db;

$q = $db->prepare("SELECT * FROM $table LIMIT 0");
$result = $db->execute($q);

foreach ($result->tableInfo() as $c)
$this->columns[$c['name']] = NULL;
}


to this:


// get a description of a table
function describe($table)
{
$db = $this->db;
$columns = array();

$q = $db->prepare("SELECT * FROM $table LIMIT 0");
$result = $db->execute($q);

foreach ($result->tableInfo() as $c)
$columns[$c['name']] = NULL;

$this->columns = $columns;
}


seems to fix it. I can't see any reason why other than what appears to
be general PHP brokenness.
If anyone has a rational explanation as to why this is so I'd be
grateful to hear it.

Regards,
Cliff
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0