Replicating the PHP include function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Replicating the PHP include function

Post 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.
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: Replicating the PHP include function

Post by MindOverBody »

Maybe you're forgeting to put echo/print function before you call you function.

Code: Select all

echo fileInclude(...);
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Replicating the PHP include function

Post 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.
Post Reply