0
votes

This is my folder structure.

enter image description here

Problem Description

I have included inner.php file of inc folder at index.php. Then I have included config.php file of inc folder at inner.php file.

When i run index.php url in browser then output show like below image. enter image description here

That output only shows "inner". That means data of config file is not displayed.

Solution can be got by the use of magic constant like __DIR__, __FILE__.

But i need to understand why this problem is created when file name is config.php.

Because when i change file name from config.php to config2.php then browser shows content of config2.php file.

See below code and output image.

Code file image

enter image description here

Output display image

enter image description here

Output shows "configinner" means data print of config file.

According above scenario you can see when i have included config2.php file then it has been included properly.

So that means config.php name file is always get from main route and it not take from inner folder at especially in PHP version 5.5.28.

Am i right or not?

1
First, let me say you should not be running anything below PHP 5.6 (even 5.6 is deprecated). That said, it is not the case in PHP 7.2; I created the same structure and everything worked fine. - Sam
@Samuel I know that this thing is working properly in PHP 7.2. But i want to know the valid reason why the config.php file is not included in PHP version 5.5.28. Can you check in specific version (5.5.28) please? - Bhavin Thummar

1 Answers

0
votes

index.php is not in the inc folder.

In order to include it, you need to include it like this:

include "inc/config.php"

config2.php is added via require if you use include, it would behave in the same manner.