directory:
myproject:
src:
MyProject:
Foo:
Foo.php
in file autoload_namespaces.php
return array(
'MyProject' => array($vendorDir . '/myproject/src'),
);
if declare look like this:
class Bar extends MyProjext\Foo\Foo
{
}
or:
use MyProjext\Foo\Foo;
class Bar extends Foo
{
}
it working, but i want declare not using 'use MyProjext\\Foo\\Foo;' or 'extends MyProjext\\Foo\\Foo'
class Bar extends Foo
{
}
this is error: 'class Foo not found', somebody can help me?
You said:
it working, but i want declare not using 'use MyProjext\\Foo\\Foo;' or 'extends MyProjext\\Foo\\Foo'
Which means this works:
use MyProject\Foo\Foo;
class Bar extends Foo
{
}
But this doesn't work (you want to make it working):
class Bar extends Foo
{
}
It's not working because the class Bar
is trying to extend the class Foo
from global scope but the class Foo
is declared under MyProject\\Foo
namespace and it's stored in MyProject/Foo
directory, so the error is happening and it's logical.
If you want to use this code (without any namespace
):
class Bar extends Foo
{
}
Then make sure that, the class Foo
is in available in the global namespace and find a line like namespace MyProject\\Foo;
before your Foo
class declaration and remove that line and also include the class Foo
before you use it (by extending) to create class Bar
. So, it could look like this:
// You may need to adjust the path
require_once("MyProject/Foo/Foo.php");
class Bar extends Foo
{
}
Use of namespace
is better so try to stick with it, without namespace
your current autoloading
technique may fail unless you rewrite it without use of namespace
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.