I am having an issue in php… I don’t fully understand how the whole require() thing works. My understanding is that it takes the current class’s member variables and makes them global inside the required file. If this is the case, then why does it not also take the base class’s member variables and make them global?
baseclass.php:
class BaseClass {
var $user;
}
myclass.php:
class MyClass extends BaseClass {
function doSomething() {
require "page.php"
}
}
page.php:
$this->user // <- this is out of scope?
$this->useris available. I just tested it.require()works as if the required file were in the require command’s place. Nothing more, nothing less.In your example, the required file gets the function’s scope.
var $varnameis old style: In PHP 5, better use one ofto declare variables.