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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:09:41+00:00 2026-06-05T11:09:41+00:00

I am writing a MVC Framework (for the purpose of learning and discovery as

  • 0

I am writing a MVC Framework (for the purpose of learning and discovery as opposed to actually intending to use it) and I have came across a slight problem.

I have a config.php file:

$route['default'] = 'home';

$db['host'] = 'localhost';
$db['name'] = 'db-name';
$db['user'] = 'user-name';
$db['pass'] = 'user-pass';

$enc_key = 'enc_key'

I load these via a static method in my boot class:

public static function getConfig($type) {
    /**
     * static getConfig method gets configuration data from the config file
     *
     * @param string $type - variable to return from the config file.
     * @return string|bool|array - the specified element from the config file, or FALSE on failure
     */
    if (require_once \BASE . 'config.php') {
        if (isset(${$type})) {
            return ${$type};
        } else {
            throw new \Exception("Variable '{$type}' is undefined in " . \BASE . "config.php");
            return FALSE;
        }
    } else {
        throw new \Exception("Can not load config file at: " . \BASE . 'config.php');
        return FALSE;
    }
}

and then load the route like so:

public function routeURI($uri) {
    ...
    $route = $this::getConfig('route');
    ...
}

which catches the exception:

"Variable 'route' is undefined in skeleton/config.php"

now, it works fine if I make the config.php file like so

$config['route']['default'] = 'home'
...

and change the two lines in the method like so:

if (isset($config[$type])) {
        return $config[$type];

I have also tried using $$type instead of ${$type} with the same problem.

Is there something I am overlooking?

  • 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-05T11:09:42+00:00Added an answer on June 5, 2026 at 11:09 am

    As written, this function can be called only once, because it uses require_once and on subsequent calls you won’t bring in the local variables defined in config.php anymore. I suspect you are getting this error on your second call to getConfig().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am going to use Spring Web MVC Framework on Netbeans. Writing Web user
I am writing a web program using mvc php framework. I have index and
I'm still writing my simple MVC for learning and eventually make a framework for
I'm writing my own MVC framework in PHP, just for learning purposes. It wasn't
I am writing an ASP.Net MVC 3 Web Application using Entity Framework 4.1. My
I'm writing a MVC website and using jqGrid. I have managed to get it
I'm currently writing a couple of MVC sites using Kohana as my framework. Each
I am using codeigniter php MVC framework to develop a web application. I have
I am writing an asp.net mvc application to learn Entity Framework with and am
I am writing Web app in java using Spring Web MVC framework. Somehow validation

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.