-1

I have file a.php and data folder in one folder. In data folder, I create two files: b.php and c.php.

a.php

<?php
   $a = 1;
   include('data/b.php');
?>

b.php

<?php
 include('data/c.php');
?>

c.php

<?php
 echo $a;
?>

When I run file a.php, result is 1. But I change content of file b.php to include('c.php'); the result of file a.php is also 1.

I think it should show an error because a.php and c.php are not in the same folder.

JJJ
  • 32,902
  • 20
  • 89
  • 102
user2693571
  • 65
  • 2
  • 8
  • 2
    Read http://php.net/include - From the folder structure `b.php` and `c.php` look like they are in the same folder, which means that in `b.php` you should `include 'c.php';`. – Sverri M. Olsen Aug 18 '13 at 09:27
  • OK, but in b.php include('data/c.php'), file a.php show 1. – user2693571 Aug 18 '13 at 09:31
  • Check this line in official doc: `If the file isn't found in the include_path, include will finally check in the calling script's own directory and the current working directory before failing.` Word `and` is there for a reason. ) – raina77ow Aug 18 '13 at 09:36
  • I'd suggest checking [this answer](http://stackoverflow.com/a/2184919/1229023) as well. – raina77ow Aug 18 '13 at 09:39

1 Answers1

-1

If you include a file, even from a subfolder the main "relative" path is still that from first file. Read more about include / require functions - they just inject script in specified place, does not change including relative path.

Tomasz Banasiak
  • 1,540
  • 2
  • 13
  • 19