Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

OOP global variables

$
0
0

Hello freaks,

 

I am having quite a difficult time working out how to use an instance of a certain class in all instances of all objects.

 

Example:

this is my main file ( index etc. ),

 

 

 

<?php

$a = new User();

$b = new HeaderBuilder($_SESSION['userid']);

?>
 

 

 

HeaderBuilder:

 

<?php
 
class HeaderBuilder{
 
    function __construct($id){
    echo $a->getUserById($id);
    }
 
}

 

Now my question is how do I use $a in HeaderBuilder's __construct without creating a new instance ?


Viewing all articles
Browse latest Browse all 13200

Trending Articles