0

Let’s say I have two files:

App/Version.php

<?php

namespace App;
const VERSION = "0.1.0";

App/Http/Controllers/AppController.php

namespace App\Http\Controllers;

use const App\VERSION;

class AppController extends Controller
{
    public function version()
    {
        return VERSION;
    }
}

With this, I’ve got "Undefined constant 'App\VERSION'" when I call AppController@version route.

I use composer. Probably, the question is about how to autoload constant...

zhekaus
  • 3,126
  • 6
  • 23
  • 46

2 Answers2

2

As composer is using, file with constants can be added to autoload as shown in this answer:

https://stackoverflow.com/a/17404435/4332851

zhekaus
  • 3,126
  • 6
  • 23
  • 46
1

You can have a third file, which is included in those 2. Usually such file is called config.php or init.php

halojoy
  • 225
  • 2
  • 7