Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list require_once()'s searched paths in PHP?

We've all seen this error before:

Warning: require_once(test/blah.inc) [function.require-once]: failed to open stream: No such file or directory in /home/narf/narf.inc on line 3

Fatal error: require_once() [function.require]: Failed opening required 'test/blah.inc' (include_path='.:/usr/lib64/php:/usr/lib/php:/home/narf/inc:/home3/narf/php:/home3/narf/inc/dev:') in /home/narf/narf.inc on line 3

Super annoying.

Here's what I'm looking for: Some sort of PHP snippet that will list the paths that are being searched for the include file.

From what I can see, I've set up my path correctly (the above include scenario is simply a fabrication), and I can include the file successfully from other portions of the project.

However, I just can't get it to work. If I had a list of locations that were being searched, I could easily track down the path that I'm missing and identify why my require/include isn't working.

Thoughts? Does someone have a snippet kicking around they could share?

Thanks a million in advance! :)

Edit: For what it's worth, I think I tracked down the problem, but if you've still got something that could help out, it would be great for future misconfigurations! :)

Edit 2: Thanks for all who have answered. Getting the include path is nice, but I'm looking for actual absolute paths of directories that are being searched. The reason why I'm being picky is because it gets confusing when using a require() or include() along with relative paths. Also, I suspect that there are some other gotchas such as (potentially) whether or not symlinks are followed on a given setup, etc.

like image 435
rinogo Avatar asked Dec 28 '22 23:12

rinogo


1 Answers

You want the function get_include_path() Documentation

like image 110
Michael Berkowski Avatar answered Jan 09 '23 12:01

Michael Berkowski