Manixat Posted March 25, 2013 Share Posted March 25, 2013 Hello freaks, I have a file structure like so Framework/App.php Framework/config.php Public/Index.php I have put "echo 'test';" in the config.php file for the purpose of testing and here's what I'm experiencing. in my index.php I include App.php like so - include('../Framework/App.php');Then in the App.php I include config.php like so - include('config.php'); And now config.php doesn't throw a warning "no such file" but doesn't echo "test" either. When I include "config.php" from "index.php" like so - include('../Framework/config.php'); Then it echoes "test". My question is why this strange behavior, why is it kind of including config from App but not quite doing what it's supposed to ? Quote Link to comment https://forums.phpfreaks.com/topic/276132-includerequire-strange-behavior/ Share on other sites More sharing options...
davidannis Posted March 25, 2013 Share Posted March 25, 2013 Is it possible that App.php exits before it gets to the include ('config.php')? Can you post some of the code from App.php? Quote Link to comment https://forums.phpfreaks.com/topic/276132-includerequire-strange-behavior/#findComment-1420962 Share on other sites More sharing options...
Manixat Posted March 25, 2013 Author Share Posted March 25, 2013 (edited) <?php require('config.php'); function __autoload($class_name) { include 'classes/' . $class_name . '.php'; } and it continues doing other stuff, which does execute. Edited March 25, 2013 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/276132-includerequire-strange-behavior/#findComment-1420964 Share on other sites More sharing options...
DavidAM Posted March 25, 2013 Share Posted March 25, 2013 The path for include is relative to the current working directory. This is usually the path of the original executing script (in this case index.php). So include('config.php');, even inside of App.php, is looking in the Public directory not the Framework directory. Why it does not throw an error, could be a couple of things: there is another config.php in the Public directory; or your error reporting value does not cover this warning; or there is a config.php somewhere else in the include_path (from the PHP.ini file). Quote Link to comment https://forums.phpfreaks.com/topic/276132-includerequire-strange-behavior/#findComment-1420968 Share on other sites More sharing options...
Manixat Posted March 25, 2013 Author Share Posted March 25, 2013 (edited) Alright that worked, but that raises another question. Since the working directory is the original working script directory ( Public ), then how come the classes get included correctly from App.php when the structure is like so: Framework/App.php Framework/config.php Framework/classes/ Public/Index.php and the include from my autoload function is like so: include 'classes/' . $class_name . '.php'; Edited March 25, 2013 by Manixat Quote Link to comment https://forums.phpfreaks.com/topic/276132-includerequire-strange-behavior/#findComment-1420972 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.