Page 1 of 1

Function access in classes

Posted: Fri Mar 25, 2011 1:47 pm
by nsweet
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:

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')
		}
	}
}
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?

Re: Function access in classes

Posted: Fri Mar 25, 2011 2:00 pm
by John Cartwright
So your saying if you use require_once, you are getting undefined function error?

Re: Function access in classes

Posted: Fri Mar 25, 2011 2:04 pm
by nsweet
Yeah...
I think what I'm going to do is continue to use require_once but just put in the top of each file instead, making session_check global. It's not an ideal solution, but I can't see any other way forward. I guess the one consolation I can afford is that since these classes are only being accessed by people with permission nothing too awful could really happen.