Page 1 of 1

Layering Classes

Posted: Thu May 29, 2008 1:18 am
by dab
Ok, What I want to do is create multiple different objects, all of the same classes, however each class is "layered"

Visually I want to have this:
Image

Each Yellow Text is a class that I included and = new ClassName;

However, I can't seem to get a new class "created" for each new variable.

For example:
Main.php

Code: Select all

 
<?php
    include "bot/_bots.php";
    
    $bot1 = new cBot;
    echo $bot1->_conn->hi;
    echo "New line test <br />";
    $bot2 = new cBot;
    echo $bot2->_conn->hi;
 
?>
 
_bots.php

Code: Select all

 
<?php
    
    class cBot {
        var $_conn;
        function cBot() {
            include "_botServ.php";
            $this->_conn = new server();
        }
    }
?>
 
_botServ.php

Code: Select all

 
<?php
    class server {
            var $hi = "Hello World<br />";
            function server() {
                echo "I've been started!<br />";
            }
            
            function getHi(){ 
                echo $this->hi;
            }
    }
?>
 
My problem is: I can't get the 2nd bot to showup or work. I'm going to guess there's a rule against that or something. So, I'd like to know what I'm doing wrong, and a way to get around/fix it.

Thanks everyone. :D

Re: Layering Classes

Posted: Thu May 29, 2008 1:45 am
by Benjamin
Are they using fsockopen? You may need to use a different port.

Re: Layering Classes

Posted: Thu May 29, 2008 9:08 am
by dab
At your post: That's all the code I have atm.

However, after further investigation (Error reporting) I found that I had something wrong with my server class. Something about redeclaring it again.

I moved the include to above the class file, and it worked as expected. :D

Code: Select all

 
     include "_botServ.php";
     class cBot {
         var $_conn;
         function cBot() {
             $this->_conn = new server();
         }
     }