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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:17:20+00:00 2026-06-12T10:17:20+00:00

I have a config file that is a php array named config.php. return array(

  • 0

I have a config file that is a php array named config.php.

return array(
    'template_dir' => __DIR__ '/configs/templates.php'
)

Then whenever I want to use this config file I would just include config.php. Its also really easy to write a config file in this way.

file_put_contents($config, 'return ' . var_export($data, true));

But I would like to be able to write the magic constant DIR to the config file without it expanding. So far I have not been able to come up with a way to do this. I have tried everything to writing a recursiveArrayReplace method to remove the entire path and trying to replace it with

    __DIR__

but it always comes up as

    '__DIR__ . /configs/template.php'

Which in that case will not expand when its ran.

How can I write

   __DIR__ to an array in a file or how ever else without the quotes so that it looks like,

array('template_dir' => __DIR__ . '/configs/templates.php');
  • 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-12T10:17:22+00:00Added an answer on June 12, 2026 at 10:17 am

    This is not possible, because var_export() prints variables, not expressions.

    It would be better to write all your paths as relative directories instead and canonicalize to a full working path after fetching the data.

    You could also consider returning an object:

    class Config
    {
        private $paths = array(
            'image_path' => '/configs/template.php',
        );
    
        public function __get($key)
        {
            return __DIR__ . $this->paths[$key];
        }
    }
    
    return new Config;
    

    Alternatively, you’d have to generate the PHP code yourself.

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

Sidebar

Related Questions

I have a config.php file that creates an array, something like $config = array(
I have an config.php file where I simply make an huge array that contains
I have a php file that looks like this: <?php include(config.php); // put the
I have set an array in my config file that I use global in
Hello guys I have this code in main.php config file: 'components' => array( '[.........]',
I have a PHP script that uploads a CSV file and then saves some
I want to display 404 error page for that i have made error404.php file
I have a php file named config.php in which I defined the application settings
I have a config file that I read using the RawConfigParser in the standard
I have a large config file (user) that i needed to go to the

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.