Storing inheritance info in a DB.

[email protected] (sjbrown)
Newsgroups php.general
Message-ID <[email protected]>
Here's my problem:

What's a good way to store information about objects that inherit in a
Database, and get them back out again?

Please, if you're good with classes, read my post, it looks long, but
it's really quite simple.

Here's my approach, but I'm getting some wonky errors, probably
out-of-scope, or accessing memory that's not mine...

Here's my Tables:
+-------------------------+
| Fruit                   |
+-------------------------+
| id | weight | fruitType |
+====+========+===========+
| 1  | 3      | Banana    |
+----+--------+-----------+
+------------------------+
| Banana                 |
+------------------------+
| id | parentID | length |
+====+==========+========+
| 1  | 1        | 5      |
+----+----------+--------+


And here's my code:
<?php

class Fruit
{
    var $weight;

    function recThaw( $id )
    {
        $s = "SELECT * FROM Fruit WHERE id = $id";
        $t = new OneTransaction;
        $t->query( $s );
        $t->next_record();

        $fruitType = $t->f("fruitType");
        #fruitType = "Banana"

        $str = "\$temp = new $fruitType;";
        eval( $str );
        #$temp = new Banana;
    
        $temp->thaw($id);
    
        $temp->weight = $t->f("weight");
    
        $this = $temp;
    }

    function whatami() { echo "<BR>Fruit"; }
}

class Banana extends Fruit
{
    var $length;

    function thaw( $parentID )
    {
        $s = "SELECT * FROM Banana WHERE parentID = $parentID";
        $t = new OneTransaction;
        $t->query( $s );
        $t->next_record();

        $this->length = $t->f("length");
    }

    function whatami() { echo "<BR>Banana"; }
}

$asdf = new Fruit;
$asdf->recThaw(1);
$asdf->whatami();
echo "<BR> asdf-weight". $asdf->weight;
echo "<BR> asdf-length". $asdf->length;

?>


Here's my output:

Banana
asdf-weight3
asdf-length<


[FYI, I'm posting to the phplib list because i know PHPLIB stores object
info in the DB somehow, thus it's possible someone there will know how
to help]


-shandy


-- 
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Shandy (Andy) Brown
http://sjbrown.geeky.net
////////////////////////////////////////////////////
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.