View Single Post
Old 01-02-2011, 08:15 PM   #1 (permalink)
Kingdom
The Visitor
 
Kingdom's Avatar
 
Join Date: Jan 2011
Posts: 3
Thanks: 1
Kingdom is on a distinguished road
Bricks Need help with array()

OK, so i have this class:
PHP Code:
<?php
class Lang extends Db {
    var 
$lang = array();
    var 
$chosen_lang;
    var 
$lang_dir;
    var 
$img_dir;
    
    function 
setLang ($chosen_lang) {
        
$this->lang_dir $_SERVER['DOCUMENT_ROOT'].'/lang/'.$this->chosen_lang.'/';
        
$this->img_dir $_SERVER['DOCUMENT_ROOT'].'/gl_imgs/'.$this->chosen_lang.'/';
        
$this->chosen_lang $chosen_lang;
        
        unset(
$chosen_lang);
    }
    
    public function 
loadLang ($file){
        if( 
file_exists$_SERVER['DOCUMENT_ROOT'].'/lang/'.$this->chosen_lang.'/'.$file.'.php' ) ) {
            include( 
$_SERVER['DOCUMENT_ROOT'].'/lang/'.$this->chosen_lang.'/'.$file.'.php' );
            
$this->lang[$file] = array();
                
            foreach (
$lang as $k => $v) {
                
$this->lang[$file][$k] = $v;
            }
        }
        
        unset(
$lang$file$k$v);
    }
}
?>
And on the index page of the website i have this:
PHP Code:
<?php
include($_SERVER['DOCUMENT_ROOT'].'classes/class_Db.php');
include(
$_SERVER['DOCUMENT_ROOT'].'classes/class_Lang.php');

$lang = new Lang;
$lang->setLang('en-us');
$lang->loadLang('website_account');
$lang->loadLang('website_main-menu');
?>
My question is: why the script won't work if i add the command:
PHP Code:
$lang->loadLang('website_main-menu'); 
If i only leave the following, the script works as intended:
PHP Code:
$lang = new Lang
$lang->setLang('en-us'); 
$lang->loadLang('website_account'); 
After some debugging, i found out that the script executes the first loadLang command on the 'website_account', but when it executes the second loadLang command ('website_main-menu'), it freezes at this line on the class:
PHP Code:
$this->lang[$file] = array(); 
Thanks in advance!
Kingdom is offline  
Reply With Quote