Is there a PHP reference manual?

I know how to include files in folders further down heirachy, but I'm having trouble finding my way back. I decided to go with the default set_include_path, everything further includes relative to level 2 paths up, but have no idea how to write it.

Is there a reference somewhere that specifies the path that links to PHP?

0


source to share


2 answers


I use dirname to get the current path and then use that as a base to compute all future path names.

For example,



$base = dirname( __FILE__ ); # Path to directory containing this file
include( "{$base}/includes/Common.php" ); # Kick off some magic

      

+2


source


it might be easier to just use the absolute path to the link:

set_include_path('/path/to/files');

      

thus you have a guideline for your entire future. including are handled relative to the point they called, which can cause some confusion in certain scenarios.

as an example, given the folder structure ( /home/files

):

index.php
test/
  test.php
test2/
  test2.php

// /home/files/index.php
include('test/test.php');

// /home/files/test/test.php
include('../test2/test2.php');

      



if you call index.php it will try to include the following files:

/home/files/test/test.php // expected
/home/test2/test2.php // maybe not expected

      

which may not be what you expect. the call to test.php will call /home/files/test2/test.php

as expected.

the conclusion is that inclusions will be relative to the original calling point. to clarify, it affects set_include_path()

if it is relative. consider the following (using the same directory structure):

<?php
// location: /home/files/index.php
   set_include_path('../'); // our include path is now /home/

   include('files/test/test.php'); // try to include /home/files/test/test.php
   include('test2/test2.php'); // try to include /home/test2/test2.php
   include('../test3.php'); // try to include /test3.php
?>

      

+1


source







All Articles