derrick24 Posted December 3, 2007 Share Posted December 3, 2007 Is this something php allows? This code works on php5.1.2 and 5.2.5. Seems to break on some 5.2.* versions The zip file contains the full set of files. <?php print "<strong>Welcome to the site, attempting to include file.</strong><hr>"; // Test1 require_once("includes/index.php"); // this file is at wwwroot/includes/index.php. The path is not wrong as this file is pulled into the root of the site iteself. if (hello() == true) // Hello sits inside "includes/index.php" { print "include worked."; } ?> [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
trq Posted December 3, 2007 Share Posted December 3, 2007 There is nothing (syntax wise) broken about your code. Quote Link to comment Share on other sites More sharing options...
derrick24 Posted December 4, 2007 Author Share Posted December 4, 2007 I know ...so you would agree with me if I say that its a bug in the php versions where this code breaks. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 What error does it throw? PhREEEk Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 Is the code you posted the index.php within the page directory? If so, you need to use... <?php print "<strong>Welcome to the site, attempting to include file.</strong><hr>"; // Test1 require_once "../includes/index.php"; if (hello() == true) { print "include worked."; } ?> Yes, your path is wrong. Quote Link to comment Share on other sites More sharing options...
derrick24 Posted December 4, 2007 Author Share Posted December 4, 2007 Im not getting an error. the function "hello()" simply does not work or run. I'm sure this has reference to this bug: http://bugs.php.net/bug.php?id=9673 to elaborate: I use this directory structure for one of my sites and my hosting company has upgraded to 5.2.2 and is no longer working. They seem to feel that I should rewrite my code. I'm not prepared, nor do I have the time to do that especially if this is a bug in that ver. of php. Quote Link to comment Share on other sites More sharing options...
derrick24 Posted December 4, 2007 Author Share Posted December 4, 2007 Sorry Thorpe its not wrong. The code you are viewing here is pulled into the root of the directory. So everything is referenced from the root. Bare in mind this code works on certain version of php and breaks on others. Namly the 5.2.* vers up to 5.2.5 from what I can tell so far. wwwroot/ - Includes/ - index.php (Holds hello function) - pages - page - index.php ( Holds the code: include("includes/index.php")) - index.php ( pulls in pages/page/index.php) So the above structure becomes: wwwroot/ - Includes/ - index.php (Holds hello function) - index.php ( now includes "pages/page/index.php" and runs the code: include("includes/index.php") ) so now we have : wwwroot/ - index.php ( thats has: "pages/page/index.php" and "includes/index.php" all together ) Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 Ah, now I see what your doing. Still don't see why its not working. Ive never had any issue and that bug which is considered bogus by the way relates to php 4(something). Quote Link to comment Share on other sites More sharing options...
derrick24 Posted December 4, 2007 Author Share Posted December 4, 2007 The structure works as follows, its a type of drill down. wwwroot/ - Includes/ - index.php (Holds hello function) - pages - page - index.php ( Holds the code: include("includes/index.php")) - index.php ( pulls in pages/page/index.php) So the above structure becomes: wwwroot/ - Includes/ - index.php (Holds hello function) - index.php ( now includes "pages/page/index.php" and runs the code: include("includes/index.php") ) so now we have : wwwroot/ - index.php ( thats has: "pages/page/index.php" and "includes/index.php" all together ) Quote Link to comment Share on other sites More sharing options...
derrick24 Posted December 4, 2007 Author Share Posted December 4, 2007 Thanks for your input thorpe. Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 Yeah, I said I see. What does... <?php echo get_include_path(); ?> Produce? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 4, 2007 Share Posted December 4, 2007 LOL. I was just going to suggest that the include path might be different when they upgraded and might not contain a dot . From the manual - Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script Quote Link to comment Share on other sites More sharing options...
derrick24 Posted December 4, 2007 Author Share Posted December 4, 2007 it produces: C:\Apps\PHP5\Pear ?? Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 Yeah, as suspected the path is broken. I'm not 100% sure on windows but it needs to be... .;C:\Apps\PHP5\Pear Paths are seperated by ; and you need the . (dot) to be the first, it points to the current (working) directory. Tell your host to install and configure php properly. Quote Link to comment Share on other sites More sharing options...
trq Posted December 4, 2007 Share Posted December 4, 2007 You could test this youself actually, by placing... <?php set_include_path('.;' . get_include_path()); ?> prior to your require calls in your root index.php file. Quote Link to comment Share on other sites More sharing options...
derrick24 Posted December 5, 2007 Author Share Posted December 5, 2007 unfortunately its still not working ... I'm still convinced its a bug with these ver of php. My host is running php 5.2.2, Id like to get a copy of the version and test it with that. Does anyone know where I can get it. Quote Link to comment Share on other sites More sharing options...
trq Posted December 5, 2007 Share Posted December 5, 2007 http://php.net/ Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 5, 2007 Share Posted December 5, 2007 There is a bug I recall reading in the php5 change log concerning the include_once/require_once having some problem in remembering where or what file they already included, but I think the net effect was that if you had more than one folder with the same name file it included the wrong one. I recommend browsing the php change log to see if there is any relevant information. Using the newest php version is always preferred instead of an earlier one. The current is 5.2.5. Quote Link to comment Share on other sites More sharing options...
derrick24 Posted December 5, 2007 Author Share Posted December 5, 2007 I cant find a link to 5.2.2 anywhere on php.net only the latest ver. ( but I have managed to get a copy of 5.2.2 now. Just have not testes it yet) and yes 5.2.5 works fine but my host does not seem to want to upgrade to it. Ill probably have to change hosts or get my own box. I also went through the change logs, there is something there about php includes not working from 5.2.* and been fixed in php 5.2.5. http://bugs.php.net/bug.php?id=41822 I'm sure its the problem. Quote Link to comment 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.