0

Is it possible to autoload constants or functions with "composer autoload"?

If yes, how do I have to name the files? If I do it the same way as with classes, it is not working.

Example:

Directory Structure

  • index.php
  • Nested/MyClass.php
  • Nested/my_function.php
  • Nested/MY_CONSTANT.php

In all three php files in Nested/, this line is present at the beginning

namespace Nested;

My index.php file looks like the following

use Nested\MyClass;
use function Nested\my_function;
use const Nested\MY_CONSTANT;

$t = new MyClass() // Works
my_function(); // Not working
echo MY_CONSTANT // Not working
Neidi
  • 66
  • 7

0 Answers0