php require / require_once pointing to another directory without ... (...)

1

Dropped a system made in 2007 for maintenance and I'm having some difficulties to make it run in my development environment (XAMPP on Windows).

It is working (partially) in the production environment (CentOS), I made a copy of the fonts exactly the way they are, but one thing caught my attention.

In the index.php at the root of the project, there is a require like this:

require("inc.Constants.php");

I found it strange, since this file does not exist at the root of the project. Within the project home directory, there is another index.php file that also makes the same reference exactly in this way (without passing a ../ before the file name).

I looked for this file throughout the project and found nothing. And as was to be expected, testing in my DEV environment, it error just at the time of that require.

So, I went to the production server and there, I searched the system for the file and found the damn thing. That was inside the php directory (/ etc / php).

So, here is my doubt. Apparently when I do not indicate a path to the file, php, in addition to looking for it in the same directory, is looking for the file inside the directory / etc / php (as if it were an executable in windows within a directory ono system path ). Has anyone seen anything like this? If so, how do I configure this?

    
asked by anonymous 20.03.2017 / 13:30

2 answers

1

As stated in the PHP documentation

Files are included (include include or require ) based on the path indicated in the constructor beyond name, if none is indicated, the parameter specified in php.ini is observed.

View documentation link

If the file is not found on any of the paths, the script directory itself and the current working directory are searched before it fails.

See getcwd ()

link

include issues a warning if it does not find a file.

require issues a fatal error.

    
14.07.2018 / 10:25
0

This is because the CentOS you are working on (probably has ) the path from $PATH set to /etc/php this way no matter where you are it will identify the path of the file as being local, because $PATH works just like the Windows environment variables.

To repeat the behavior you can do two things:

  • Put the file in the root of your project (along with the two files that require it), but in this case if there is any file inside the project that requires this file it will not work either, then you will need to go to second way
  • Put in your environment variables ( Windows+Pause Break , or right click on start and Sistema > Configurações avançadas do sistema > Variáveis de ambiente , search for Path ) any directory you want to use as base, for example C:\Users\SeuUsuario\Desktop\PHPLib and play file in there.
20.03.2017 / 13:55