Answer the question
In order to leave comments, you need to log in
How to register a class in PHP?
Hello.
I have
not encountered this problem before, but now I have. I wrote a class in php, everything is ok.
I registered the namespace through the IDE - I checked it, it is specified correctly, the bonds see the class, everything is connected correctly:
<?php
use test\Test;
...
?>
Test.php
is in the "test"<?php
namespace test;
class Test
{
...
}
?>
Answer the question
In order to leave comments, you need to log in
Use Composer and include the required class via autoload
The word use
does not include the class file, it is needed to limit the namespace
because use imports names and doesn't load files
, that's how it will work
<?php
require_once 'test\Test.php';
use test\Test;
$a = new Test;
var_dump($a);
?>
<?php
require_once 'test\Test.php';
$b = new test\Test;
var_dump($b);
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question