0
Hello, I’m trying to use the namespace
and the use
but is resulting in Not found
Error: Fatal error: Uncaught Error: Class 'app\lib\Teste' not found in C:\xampp\htdocs\index.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\index.php on line 5
index php.:
<?php
require_once './vendor/autoload.php';
use \app\lib\Teste;
new Teste();
?>
htdocs/app/lib/Teste.php
<?php
namespace app\lib;
class Teste {
public function __construct() {
echo "Hello world";
}
}
?>
Composer.json
{
"require": {
"php": ">=5.3.3"
},
"require-dev": {
"phpunit/phpunit": "^4.3"
}
}
So you can use this:
new Teste();
, first do this:use \app\lib\Teste AS Teste;
, this is the first problem, see if it works.– Jakson Fischer
Hello, thank you for the answer, I’ve tried this and still nothing.
– João Gabriel Costa
Post the Composer.json as well
– Marcos Xavier
{
 "require": {
 "php": ">=5.3.3"
 },
 "require-dev": {
 "phpunit/phpunit": "^4.3"
 }
}

– João Gabriel Costa
See if you can get help https://answall.com/questions/40051/como-usar-namespace-numa-classe/40511#40511
– Benilson
Opa thanks for the reply, still nothing , I tried to do this:
new app\lib\Teste();
and it hasn’t yet, I don’t understand why it’s not found because there is this directory and this class.– João Gabriel Costa
try calling app lib only
– Diêgo Correia de Andrade
If I call only the
use app\lib;
and after that I call thenew Teste();
return this:Fatal error: Uncaught Error: Class 'Teste' not found in C:\xampp\htdocs\index.php:13 Stack trace: #0 {main} thrown in C:\xampp\htdocs\index.php on line 13
, i think it must be some . php extension problem in use or something like.– João Gabriel Costa
You need to set autoload on your Composer.json first
– gmsantos
If you are using Composer you should run Composer dump-autoload after creating the classes for the mapping to be updated.
– Laiane Hermes