Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:14:56+00:00 2026-05-26T08:14:56+00:00

Need some help with inclusion of outside variables. I have this file lang.class.php class

  • 0

Need some help with inclusion of outside variables.

I have this file lang.class.php

class Lang {
    public $DefaultLang = 'en';

    public function __construct() {
        require_once($_SERVER['DOCUMENT_ROOT'] . "/system/lang/en.php");
    }

    public function MainLang() {
        return $this->DefaultLang;
    }

    public function Translate($String, $Array = "") {
        if($Array != '')
            $LangArray = $Array;

        echo $LangArray[$String];
    }

    public function __destruct() {}
}

The language file is included in the __construct()

And this file en.php which holds an array

$LangArray = array(
    "home" => "Home",
    "news" => "News",
    "info" => "Info"
);

The class is called by this: $Lang->Translate('home').

This returns nothing, but if I do this $Lang->Translate('home', $LangArray), it returns the value from the array_key home

So, how can I get the array without getting it via the function?

Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:14:56+00:00Added an answer on May 26, 2026 at 8:14 am

    When you use require_* or include_*, think about it like if the code in the included file would simply be pasted instead of the include directive. Therefore, if you include that file, you will have a variable called $LangArray. You can take that variable and assign it to a private property in the class, then use it.

    class Lang {
        private $LangArray; // <- store the array in a private property
    
        public function __construct() {
            require_once($_SERVER['DOCUMENT_ROOT'] . "/system/lang/en.php");
            $this->LangArray = $LangArray; // <- assign the loaded array
        }
    
        public function Translate($String) {
            echo $this->LangArray[$String]; // <- use the loaded array
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help. I am creating a SelectItem class like this: public class
Need some help about with Memcache. I have created a class and want to
Need some help to solve this. I have a gridview and inside the gridview
need some help figuring this out. My function: function cleanDatabase() { $allowedTime = $this->time
Need some help with putting this query together. I'm using Mysql I have two
Need some help refactoring this code: $(span[rel=color_content]).ColorPicker({ onChange: function (hsb, hex, rg) { $(span[rel=color_content]).css('background-color',
need some help with this one. I have some reflectance values for a colour
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help with this problem in implementing with XSLT, I had already implemented
Need some help gathering thoughts on this issue. Our team is moving ahead with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.