-2

I have a translate system:

/phps/languages.php

$root = $_SERVER['DOCUMENT_ROOT']; 
if($lang == "en-us"){
    include_once("$root/site-languages/en-us.php"); // include en-us
}

this function: /phps/date.php

function time_difference($date){

$root = $_SERVER['DOCUMENT_ROOT']; 
include_once("$root/phps/languages.php");

echo $language_include_variable; // it is empty

and my page.php that will call date.php and date calls languages.php.

$root = $_SERVER['DOCUMENT_ROOT']; 
include_once("$root/phps/date.php");

The problem is the echo $language_include_variable is null. any ideas?

RGS
  • 4,062
  • 4
  • 31
  • 67

1 Answers1

1

It's due to include_once. The file will only be included once in the lifetime of the script, and therefore be accessible in the function scope only once.

On subsequent calls of the function the file will not be included anymore and thus the variable will not be in the scope of the function anymore.

Decent Dabbler
  • 22,532
  • 8
  • 74
  • 106