Function access in classes
Posted: Fri Mar 25, 2011 1:47 pm
So I have a weird problem that has been bothering me. I have a set of Classes in a framework that I've been building that can only be utilized by someone who has permission. Each class has it's own file. Upon the loading of that file the file requires another file called "session_check", which contains a function called "session_check", I probably don't need to elaborate on what this function does. The problem? I am starting to build a few classes in this internal class schema that call on one another example:
The problem is described in the code above, but I'll go over it if you don't care to look at the code and are still tracking with me. If I require instead of require_once the "session_check.php" file then an error occurs because I'm declaring the same function twice, if I use require_once instead then Another_class doesn't have access to session_check anymore. Extending the classes is not an option. What should I do?
Code: Select all
<?php
class Some_class{
function __construct(){
require('session_check.php')
if(session_check()){
//this is a function that loads internal classes specifically, so before anybody jumps on me about trying not using autoload
//I actually want loading internal classes to look like this, so that it can only be done in the framework.
loadIntClass('another_class');
//Here's the problem: this class throws an error because session_check has already been loaded, if I substitue with require_once
//then all of a sudden Another_class doesn't have access to session_check
$var = new Another_class('asdfasd');
}
else{
die('your session has expired')
}
}
}