# Problems with object oriented script execution

**URL:** <https://forum.kirupa.com/t/problems-with-object-oriented-script-execution/242755>\
**Category:** Uncategorized\
**Created:** [October 30, 2007, 2:16am UTC](https://forum.kirupa.com/t/problems-with-object-oriented-script-execution/242755 "2007-10-30T02:16:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![boondocksaint2k](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/boondocksaint2k/32/3453_2.png) [@boondocksaint2k](https://forum.kirupa.com/u/boondocksaint2k)\
**Post date:** [October 30, 2007, 2:16am UTC](https://forum.kirupa.com/t/problems-with-object-oriented-script-execution/242755/1 "2007-10-30T02:16:39Z")

</div>

I have a catalog class.

```php
class Catalog {

    private $db;
    private $categories = array(); // array of categories
    
    function Catalog($db) {
        $this->db = $db;
        $this->getCategories();
    }
    
    private function getCategories() {
        $result = $this->db->query('SELECT c.id, c.name FROM categories c');
        while ( $row = $result->fetch_row() ) {
            $this->categories[] = new Category($this->db, $row[0], $row[1]);
        }
    }
    
    public function categories() {
        return $this->categories();
    }
    
    public function test() {
        echo $this->categories[0]->id();
    }
    
}

```

And a category class.

```php
class Category {

    private $db;
    private $id;
    private $name;
    private $items = array(); // array of items
    
    function Category($db, $id, $n) {
        $this->db = $db;
        $this->id = $id;
        $this->name = $n;
        $this->getItems();
    }

    private function getItems() {
        $query = 'SELECT i.id, i.name, i.datetime FROM items i, catalog
                    WHERE i.id = catalog.item_id AND catalog.category_id = '.$this->id;
        $result = $this->db->query($query);
        while ( $row = $result->fetch_row() ) {
            $this->items[] = new Item($this->db, $row[0], $row[1], $row[2]);
        }
    }
    
    public function id() {
        return $this->id;
    }
    
    public function name() {
        return $this->name;
    }
    
    public function items() {
        return $this->items;
    }
    
}

```

And an item class.

```php
class Item {

    private $db;
    private $id;
    private $name;
    private $datetime;
    
    function Item($db, $id, $n, $dt) {
        $this->db = $db;
        $this->id = $id;
        $this->name = $n;
        $this->datetime = $dt;
    }
    
    private function get($column) {
        return $column;
    }
    
    public function id() {
        return $this->id;
    }
    
    public function name() {
        return $this->name;
    }
    
    public function datetime() {
        return $this->datetime;
    }
    
}

```

And I’ve got an index.php with the following:

```php

$db = new Database(HOST, USERNAME, PASSWORD, DATABASE);
$catalog = new Catalog($db);
foreach ( $catalog->categories() as $category ) {
     foreach ( $category->items() as $item ) {
         echo $item->datetime();
     }
}

```

And when I tried running it on IIS7, Vista, I got a stack overflow error so I switched to Apache 2.2.6 with PHP 5.2.4. …and that didn’t help anything. By the way, everything that needed to be included is included and calling $catalog-\>test(); works fine.

Any ideas?
