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 7833189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:35:50+00:00 2026-06-02T12:35:50+00:00

This is the code: class app { public $conf = array(); public function init(){

  • 0

This is the code:

class app {
    public $conf = array();
    public function init(){
       global $conf;
       $conf['theme']   = 'default';
       $conf['favicon'] = 'favicon.ico';
    }
    public function site_title(){
        return 'title';
    }
}

$app = new app;
$app->init();


//output
echo $app->conf['theme'];

And I get this error:

Notice: Undefined index: theme in C:\xampp\htdocs\...\trunk\test.php on line 21

Where have I gone wrong, and is there any simpler way to get same result?

  • 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-06-02T12:35:52+00:00Added an answer on June 2, 2026 at 12:35 pm

    You are in the wonderful world of OOP, no longer do you have to use global!

    Try this:

    class app
    {
        public $conf = array();
    
        // Notice this method will be called every time the object is isntantiated
        // So you do not need to call init(), you can if you want, but this saves
        // you a step
        public function __construct()
        {       
            // If you are accessing any member attributes, you MUST use `$this` keyword
            $this->conf['theme']   = 'default';
            $this->conf['favicon'] = 'favicon.ico';
        }
    }
    
    $app = new app;
    
    //output
    echo $app->conf['theme'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider this code : class App { public static function log($msg) { echo $msg;
I wrote this code in order to make a soundboard like app public class
I have this code: public partial class App : Application { protected override void
There is this code: class SomeClass { public: SomeClass(){} SomeClass(SomeClass& b){} SomeClass(SomeClass&b, SomeClass& c){}
I have this code : class Event{}; class CustomEvent:public Event{}; class Handler { public:
This code works: class Test { public: Test(string name) : _name(name) {}; bool operator()()
I use the following code in wcf ria services (Silverlight App): public partial class
I'm trying to compile a POCO with this code public class MenuItem { public
I have this code //file Globals.cs in App_Code folder public class Globals { public
I am creating a database in android using this code: public class PackageDBHelper extends

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.