i have in my composer.json:
"autoload": {
"files": [
"test.php"
]
}
the content of test.php is:
<?php
function foo(){
echo 'Hello World';
}
in my index.php i have this:
<?php
require_once dirname(__DIR__) . '/vendor/autoload.php';
foo();
but i get Call to undefined function foo()
everything that is declared as a file in the autoload is supposed or expected to be added… in this case I expected it to work as a require_once, what am I doing wrong??
Update
after several attempts; the IDE suggests me to use this:
use function /foo
This was not necessary before…
>Solution :
This happens because you have surely declared a namespaces in your test.php; if you remove the namespace it will stop indexing your methods under a namespace and they will remain public/global, I don’t know if this is documented somewhere… but it had already happened to me.