How do I call a function which is in a different file without including or requiring that file?
3 Answers
You can't. If you don't include or require it, PHP has no idea what's there. You can use .htaccess or php.ini to automatically include a file, which is identical to including it with require or include.
For example in .htaccess
php_value auto_prepend_file "/full/path/to/a/prepend-file.php"
In php.ini
auto_prepend_file = "/full/path/to/a/prepend-file.php"
2 Comments
Mustafa Mansoor
can u explane?? please describe how to edit php.ini of server machine??
David Fells
Depends on the OS and how PHP was installed, and the web server. For example, on my Ubuntu 11 workstation, it's /etc/php5/php.ini after installing with aptitude. Find it, edit it.
Read it into a string and eval it.
$code = file_get_contents("somefile.php");
eval($code);
1 Comment
Wh1T3h4Ck5
+1 well, with some restrictions in PHP file, this will work fine ;)
Copy and paste it. But mind the license.
1 Comment
Mr. Zen
You violate one of the first software engineering principles that way. Reusuability.
$path_determine = explode ("/", $_SERVER['PHP_SELF']); $totSlash = 4; $RelativePath = str_repeat("../", count($path_determine)-$totSlash+1);