Jump to content

Strange behaviour with class


Ninjakreborn

Recommended Posts

I have a debug class within portable_framework.php.

<?php
class Debug {
function print_multiple($title, $array, $title2 = 'empty', $array2 = array(), $title3 = 'empty', $array3 = array(), $title4 = 'empty', $array4 = array()) {
	echo $title.'<br />';
	echo '<pre>';
	print_r($array);
	echo '</pre>';
	echo '<br />';
	if ($title2 != 'empty') {
		echo $title2.'<br />';
		echo '<pre>';
		print_r($array2);
		echo '</pre>';
		echo '<br />';
	}
	if ($title3 != 'empty') {
		echo $title3.'<br />';
		echo '<pre>';
		print_r($array3);
		echo '</pre>';
		echo '<br />';
	}
	if ($title4 != 'empty') {
		echo $title4.'<br />';
		echo '<pre>';
		print_r($array4);
		echo '</pre>';
		echo '<br />';
	}
}
}
$debug = new Debug();
?>

This is a very simple test case to prove my point.

I have this portable_framework.php included at the top of my master file..results.php.  In results.php right after the require of that class file it

let's me access that class. I have another file called "link_parser.php" that is included in the results.php further down.  This is setup to allow me

to cut my code up some so it's not all in one place.  Here is hte issue. I can't access my Debug class inside hte link_parser.php at all.

It's like the class being required into the results.php is accessible there, but not in other files that are included later on. Is that normal, and if so

is there a way I can include a class file and have it work throughout the entire system..even if there are a few levels of includes?

Link to comment
Share on other sites

By the way, I mis-told you on part of that. I can access it in those other files, just not inside of functions.  This is related to scope. Is there a way I can make that class global. SO it'll be usable in and out of any functions. I may want to throw a few debug calls right inside of other functions that are dealing with loops and it's ignoring that..I don't want to have to pass my class by reference to every function or it'll just defeat the purpose of the time I am trying to save.  IS this possible?

Link to comment
Share on other sites

Is your question about the Debug class (that you generously posted) or is it about an include problem, because reading and re-reading your situation isn't doing anything for me except confuse me.

 

Just from my understandings... you are trying to include a file with a class in it.. and then include that file (including the class) into another file... and use the class..  Or are you trying to pass an object around?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.