Slips Posted November 11, 2010 Share Posted November 11, 2010 Hi sorry for the trouble guys but i'm really stuck on this one, and i've tried everything i can. (I've been using php only for sometime now) I'm stuck at this code and can't figure out why this is failing. Objective of the script : To try and include BOTH files or throw and exception if even one fails. I tried : Including just one at a time. Its fine, so i know the path is correct. I tried a if (! (expr1 && expr2) ) statement to check if the syntax is correct to create a everything or nothing logic. $offlineLibraryPath = '/var/www/common/lib'; // Attempt to include the files try { if(! ( require_once($offlineLibraryPath.'/variables/all.php') && require_once($offlineLibraryPath.'/functions/all.php') ) ) { throw new Exception ('Including all the common library files failed.'); } } catch (Exception $e) { echo '<b>Error</b> :'.$e->getMessage(); } I get this error : Warning: require_once(1): failed to open stream: No such file or directory in /var/www/common/lib/startupIncludes.php on line 18 Fatal error: require_once(): Failed opening required '1' (include_path='/var/www/common/lib/: /var/www/culturesque/lib/: /var/www/mine/lib/') in /var/www/common/lib/startupIncludes.php on line 18 Thanks in advance for the help! Quote Link to comment https://forums.phpfreaks.com/topic/218391-invalid-require-path-error-if-i-use-in-ifelse-logic/ Share on other sites More sharing options...
ManiacDan Posted November 11, 2010 Share Posted November 11, 2010 You'd be better off with the file_exists function. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218391-invalid-require-path-error-if-i-use-in-ifelse-logic/#findComment-1133035 Share on other sites More sharing options...
trq Posted November 11, 2010 Share Posted November 11, 2010 None of the include / require family return a bool on success or failure. Quote Link to comment https://forums.phpfreaks.com/topic/218391-invalid-require-path-error-if-i-use-in-ifelse-logic/#findComment-1133039 Share on other sites More sharing options...
Slips Posted November 11, 2010 Author Share Posted November 11, 2010 @ManiacDan : I need the require to happen successfully or return an error. If i use file_exists, won't i need to use a require after that to include the file (bringing us back to check if the require will happen successfully). Ahh, i get it now , all this while echo include(filename); would always return 1, fooling me into thinking its the boolean return, when its actually the return value in filename. Adding a return false in the included file proved this for me. Thanks thorpe Quote Link to comment https://forums.phpfreaks.com/topic/218391-invalid-require-path-error-if-i-use-in-ifelse-logic/#findComment-1133044 Share on other sites More sharing options...
ManiacDan Posted November 11, 2010 Share Posted November 11, 2010 It doesn't seem like you understand what the include/require functions actually do. When you include a PHP file, basically what happens is PHP copies the contents of the file right into the script that's including them. Include/require will ALWAYS succeed if the file is present, the only question you should have is whether or not the PHP inside the included file is valid. This is something you have to ensure by writing good code in your include files, not by wrapping them in a validator. Include files shouldn't "return" anything to the parent file, because they're designed to operate as if the code is IN the parent file to begin with. -Dan Quote Link to comment https://forums.phpfreaks.com/topic/218391-invalid-require-path-error-if-i-use-in-ifelse-logic/#findComment-1133052 Share on other sites More sharing options...
Slips Posted November 11, 2010 Author Share Posted November 11, 2010 It doesn't seem like you understand what the include/require functions actually do. When you include a PHP file, basically what happens is PHP copies the contents of the file right into the script that's including them. Include/require will ALWAYS succeed if the file is present, the only question you should have is whether or not the PHP inside the included file is valid. This is something you have to ensure by writing good code in your include files, not by wrapping them in a validator. Include files shouldn't "return" anything to the parent file, because they're designed to operate as if the code is IN the parent file to begin with. -Dan yep yep, i get it now, all this while i mistook require/include for a function because of the () that it uses. Quote Link to comment https://forums.phpfreaks.com/topic/218391-invalid-require-path-error-if-i-use-in-ifelse-logic/#findComment-1133145 Share on other sites More sharing options...
trq Posted November 11, 2010 Share Posted November 11, 2010 i mistook require/include for a function because of the () that it uses. You don't have too (and probably shouldn't) use braces around there arguments. Quote Link to comment https://forums.phpfreaks.com/topic/218391-invalid-require-path-error-if-i-use-in-ifelse-logic/#findComment-1133200 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.