Layering Classes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dab
Forum Newbie
Posts: 7
Joined: Tue May 20, 2008 1:09 am

Layering Classes

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Layering Classes

Post by Benjamin »

Are they using fsockopen? You may need to use a different port.
dab
Forum Newbie
Posts: 7
Joined: Tue May 20, 2008 1:09 am

Re: Layering Classes

Post 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();
         }
     }
 
Post Reply