topherg
topherg

Reputation: 4293

global variable is being identified as null

I have a script which similar to this:

foo.php

class Foo
{
    function Foo() {
        $Registry = array();
        include 'bar.php';
        $Registry['bar'] = new Bar();
    }
}

bar.php

class Bar
{
    function Bar() {
        global $Registry;
        print_r(var_dump($Registry));
    }
}

but that returns:

array
  'Registry' => &null

Does anyone have any suggestions as to why it's not identifying the Registry variable as an array?

Upvotes: 0

Views: 77

Answers (3)

Slemgrim
Slemgrim

Reputation: 957

you have to create $register global and outside of your class

$Registry = array();

class Foo
{
  function Foo() {
    global $Registry;
    include 'bar.php';
    $Registry['bar'] = new Bar();
  }
}

bar.php

class Bar
{
  function Bar() {
    global $Registry;
    print_r(var_dump($Registry));
  }
}

Upvotes: 2

BenM
BenM

Reputation: 53198

Because $Registry does not exist, Foo->Registry exists, but that should be access from the object itself.

Upvotes: 0

knutole
knutole

Reputation: 1787

Try global in both functions, perhaps.

Upvotes: 0

Related Questions