tags:

views:

68

answers:

3

Hi guys, I have some files:

core.php:

require_once 'logger.php';
require_once 'smth_else.php';

$Logger = new Logger();
$Else = new Smth_else();

smth_else.php:

...
$Logger->write(...);
...

And get:

Notice: Undefined variable: Logger in smth_else.php...

+3  A: 

The order of setting the variables and requiring your files matters. This will work:

require_once 'logger.php';
$Logger = new Logger();
require_once 'smth_else.php';
$Else = new Smth_else();
molf
It doesn't help me in updated code. Could you revise it, please?
Ockonal
+2  A: 

code in 'smth_else.php' is executed on inclusion, that is at require_once. At that stage you don't have $Logger defined.

SilentGhost
+1  A: 

You must define $logger before the inclusion of smth_else.php. Think of an inclusion as is you were pasting it into the including context.

Palantir