Page 1 of 1

Replicating the PHP include function

Posted: Thu Sep 23, 2010 3:22 am
by Sindarin
I am trying to do,

Code: Select all

$localPath = getcwd().'\\';

function fileInclude($file, $required = false)
{
	if($required == true)
	{return require($localPath.$file);}
	else
	{return include($localPath.$file);}
}
But it doesn't print the contents of the page that was included.

Re: Replicating the PHP include function

Posted: Thu Sep 23, 2010 6:11 am
by MindOverBody
Maybe you're forgeting to put echo/print function before you call you function.

Code: Select all

echo fileInclude(...);

Re: Replicating the PHP include function

Posted: Thu Sep 23, 2010 6:42 am
by requinix
Enable display_errors and set error_reporting to -1. Then try including with $required=true.

Also, $localPath isn't available inside the function. Which won't actually make any difference (besides the possible undefined variable warning) because require/include use the CWD anyways.