Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

RKAN07's avatar

Cannot access variable in config file from a another config file

Hello,

i recently moved my laravel application to a new server (php version are the same). I have a problem (only on the new server) with the config files located under app/config, I have a config file A and a config file B. The config file b is getting a value from config file a. But on the new server they can not access the value from config file A.

Any ideas why this happens? On my old server this works with any problems. I'm using Laravel 5.

I think the config_file_a is loaded after config_file_b can this happen?

Example:

Config File A:

<?php
return array(
    'value' => 'abc'
);

Config File B:

return array(
    'key'   => 'test',
    'value' => config('config_file_a.value') // this is not working on the new server
);

Ps.: Sorry for my bad english. I hope you can understand my problem.

0 likes
6 replies
kingpabel's avatar

can you please try this way to get config value

Config::get('config_file_a.value');
RKAN07's avatar

I tried this, but getting this error:

Fatal error: Class 'Config' not found in ...
pmall's avatar

You cant do this. Config is not accessible from config. You may put this value in the .env file and use env('your_value_name', 'default_value');.

RKAN07's avatar

But the function config() is accessible on my old server. I want just understand the problematic here...why the same code not works on my new server.

pmall's avatar

No idea maybe for some reason it included config files in different order. You should really use env variables here.

RKAN07's avatar

Same here, why are the config files included in different order and how i can change this order.

My workaround is: config_file_b.php

$c['config'] = include('config_file_a.php');

return array(
    'key'   => 'test',
    'value' => $c['config']['value']
);

And yes i can use env variables but this are variables that are not enviroment specific and i have over 200+ values there :)

1 like

Please or to participate in this conversation.