I have two files: index.php and load.php (which is a class).
I'm currently managing the languages. In the index.php I call the language this way:
include_once('load.php'); $load = new load(); include_once($load->language()); Then I can just simply use:
echo $lang['name']; echo $lang['address']; //etc My question is..how do I use this inside the class load.php? I've tried so far:
include_once($this->language()); $lang['name']; retrieves: Notice: Undefined variable: lang $yo = include_once($this->language()); // retrieves $yo = bool(true) -> but I can't get info from the variable $yo The function language() only retrieves the correct file according to the Cookie.
$content = 'languages/en.php'; // or $content = 'languages/fr.php'; return $content; EDIT: to be more clear:
languages/en.php
$lang = array(); $lang['name'] = 'Your name:'; $lang['address'] = 'Your address:'; index.php
include_once('load.php'); $load = new load(); include_once($load->language()); // $load->language() == 'languages/en.php'; echo $lang['name']; // works echo $lang['address']; // works load.php
public function display(){ include_once($this->language()); var_dump($this->lang) // returns NULL var_dump($this->lang['name']) // returns NULL // I call this function in index.php } I've tried to use:
return $lang without success.
Edit 2: Looking at the answer of @Saurabh Sinha
the thing you are trying is not right. you cannot use the variable declared outside the function unless it is declared in the class. and in your case too $lang variable is outside the class and the function. you are able to access the same from index file just because when the language function is called it gives $lang variable is index file which is not a class
Which is very clear, I've join the chat with him and we conclude that the best alternative would be the define function.
define('name', 'Your name:')