I think I've made a quite obvious mistake it's just I can't figure out what it is.
For some reason php doesn't seem to like me referencing external global (is it global?) variables from inside a constructor of another class in another file. Here are my three files and their corresponding contents, I've written two copies of "loadSecond.php" one that works and one that does not but I'd like it to.
I'm using v5.2.3
index.php
Code: Select all
<?php
include_once "loadFirst.php";
include_once "loadSecond.php";
?>Code: Select all
<?php
class FirstLoaded
{
function test()
{
echo "hurrah!";
}
}
$FirstLoaded = new FirstLoaded();
?>Code: Select all
<?php
class foo
{
function __construct()
{
$FirstLoaded->test();
}
}
$foo = new foo();
?>Code: Select all
<?php
$FirstLoaded->test();
?>thank you for any possible help.Notice: Undefined variable: FirstLoaded in C:\Inetpub\wwwroot\new\loadSecond.php on line 6
Fatal error: Call to a member function test() on a non-object in C:\Inetpub\wwwroot\new\loadSecond.php on line 6