Can constants be added as a parameter to a require_once in php?

0

Good morning, I'm starting in this PHP, I have a doubt, to add files to a php is necessary to do the following:

require_once '../rutafichero/fichero.php';

My question is, assuming that at some point you have to change the name of the file path or the same name of the file and you do not want to be updating all the PHP that include that file, there is some way to put a constant instead of the route? For example do the following:

define('fichero','../rutafichero/fichero.php');

and then

require_once fichero;

I tried it but it marks me an error, so I turn to ask if there is any way to do what I try.

Thank you in advance to everyone.

PS: Working with Windows and PHP 7.

    
asked by Carlos Daniel Zárate Ramírez 12.06.2018 в 19:16
source

2 answers

0

I already found the error, I omitted mentioning that the constants were in another PHP file, first I had to include the file and then call the constant.

    
answered by 12.06.2018 в 19:43
0

I would not have to give you an error.

define('c', '../../fend/controlador_.php');
require_once c;

It is possible that the error is on another side, or wrongly specified route.

in windows there are problems with slash. ./../ could be equal to .\..\..

$slash = (substr(strtolower(php_uname('s')),0,3) == 'win') ? "\" : "/";
require($_SERVER['DOCUMENT_ROOT']."{$slash}algo.php");
    
answered by 12.06.2018 в 19:25