john45 Posted August 16, 2008 Share Posted August 16, 2008 Is it possible to use a php function that I created in another file without using include or require? I know include_path only refers to the folders/directories. Quote Link to comment https://forums.phpfreaks.com/topic/119974-include-and-require/ Share on other sites More sharing options...
revraz Posted August 16, 2008 Share Posted August 16, 2008 And it's bad to use include why? Quote Link to comment https://forums.phpfreaks.com/topic/119974-include-and-require/#findComment-618038 Share on other sites More sharing options...
john45 Posted August 16, 2008 Author Share Posted August 16, 2008 I never said it was bad. I asked if it was possible. Quote Link to comment https://forums.phpfreaks.com/topic/119974-include-and-require/#findComment-618098 Share on other sites More sharing options...
Mchl Posted August 16, 2008 Share Posted August 16, 2008 But why would you need anything else? I can imagine a system that would looad a txt file and then create a lambda function ( create_function() )based on its contents but... what for? Quote Link to comment https://forums.phpfreaks.com/topic/119974-include-and-require/#findComment-618112 Share on other sites More sharing options...
wildteen88 Posted August 16, 2008 Share Posted August 16, 2008 Is it possible to use a php function that I created in another file without using include or require? I know include_path only refers to the folders/directories. To answer the question no. How would PHP know where the function is defined? Quote Link to comment https://forums.phpfreaks.com/topic/119974-include-and-require/#findComment-618140 Share on other sites More sharing options...
ignace Posted August 16, 2008 Share Posted August 16, 2008 @wildteen wouldn't it be possible using spl_autoload()? Quote Link to comment https://forums.phpfreaks.com/topic/119974-include-and-require/#findComment-618141 Share on other sites More sharing options...
wildteen88 Posted August 16, 2008 Share Posted August 16, 2008 @wildteen wouldn't it be possible using spl_autoload()? That will only work for classes not functions. Quote Link to comment https://forums.phpfreaks.com/topic/119974-include-and-require/#findComment-618142 Share on other sites More sharing options...
ignace Posted August 16, 2008 Share Posted August 16, 2008 true, but maybe john really wanna put in all effort to not use include (or atleast only once and out of sight) i even believe that is what he is referring to in that case: // assuming set_include_path() has already been set function __autoload($className) { require_once($className . ".php"); } // no include or require required, just use: $class = new MyClass(); Quote Link to comment https://forums.phpfreaks.com/topic/119974-include-and-require/#findComment-618144 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.