class design – implementation of relations between classes in oop php – Education Career Blog

I am new in PHP with classes. I am coding an network ip-mac-user logging system integrated with dhcp. I have users, subnets, units. I created classes for each and created parameters and functions to fill the parameters and some mysql codes about what they do. but there are relationships among these classes. where can I put these relations’ codes, functions, for example there are m-n relations between subnets and units, where should I put the relationship codes?


In the class that relates to the other class. Just make sure you don’t have circular references or you will run into memory trouble.

class Adult {
    private $children = false;
    public function get_children() {
        // This is where you get the related instances
        if ($this->children === false) {
            $this->children = db_fetch('children', $this->get_id()); 
        return $this->children;


Are you asking how to store associations? If so:

Leave a Comment