Page 1 of 1

Array info dissapears when using functions and ob_start

Posted: Wed Apr 26, 2006 5:09 am
by guarriman
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi.

I created these PHP scripts, in order to execute 'foo.php' by using 'ob_start' via another script ('admin.php').

'foo.php' requires some libraries ('functions_for_foo.php' where some arrays are handled) and 'admin.php' requires other libraries ('functions_for_admin.php').

array_info.php

Code: Select all

$myList = array ("John", "Mary");
foo.php

Code: Select all

require_once("array_info.php");
require_once("functions_for_foo.php");
manageArray();

functions_for_foo.php

Code: Select all

function manageArray()
{
	global $myList;
	print_r($myList);
}

admin.php

Code: Select all

// OPTION 1
// require_once("functions_for_admin.php");
// doInclude();
// END OPTION 1


// OPTION 2
ob_start();
chdir('/usr/local/httpd/htdocs/');
include('/usr/local/httpd/htdocs/foo.php');
$out = ob_get_contents();
ob_end_clean();

print "<li>GOT CONTENTS:\n";
print $out;
// END OPTION 2
functions_for_admin.php

Code: Select all

function doInclude()
{
	ob_start();
	chdir('/usr/local/httpd/htdocs/');
	include('/usr/local/httpd/htdocs/foo.php');
	$out = ob_get_contents();
	ob_end_clean();
	
	print "<li>GOT CONTENTS:\n";
	print $out;
}
If I execute 'admin.php' with 'OPTION 2' (without calling 'functions_for_admin.php'), I can display info ($out) from array, but I use 'OPTION 1' (calling 'functions_for_admin.php'), this info dissapears.

Just the same if I don't call 'functions_for_foo.php' within 'foo.php' (got array info if I don't call functions).

Any similar experience?

Thank you very much.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]