2
I’m trying to use the classless namespaces with the Poser autoload, but I believe it is failing, for example:
/Foo/Bar.php
namespace Foo\Bar {
function baz() {
echo 'Funcionou';
}
}
/index php.
require './vendor/autoload.php';
Foo\Bar\baz();
Running the index file generates the following error:
Fatal error: Uncaught Error: Call to Undefined Function Foo Bar Baz() in /[...]/basic/index.php on line 5
but if I previously include the file:
/index php.
require './Foo/Bar.php';
Foo\Bar\baz();
So it works. I believe when calling Foo\Bar\baz
he’s trying to include the file Foo\Bar\baz.php
, but I’m not sure
My autoload on composer.json
:
"autoload": {
"psr-4": {
"Foo\\": "./Foo"
}
}
I did the dump-autoload
Use is in a framework, where the user can create routes by passing a function with its namespace to be executed (for example, Router::get('/foo', 'App\Foo\get');
), as there is usually no need to save status, the class becomes unnecessary. Use of property files
Poser solves the problem, but does not allow Lazy load (load only what is used, that is, on demand), which can mean many files included for nothing
Cade the file Composer?
– novic
@Virgilionovic the
composer.json
? It’s practically blank like I said– Costamilam
So, it won’t work if it’s blank so it doesn’t carry anything!
– novic
@Virgilionovic altered the file as I imagine it should and I guessed at the question
– Costamilam