4334738290
4334738290

Reputation: 393

Extending a class with a namespace is saying class not found

I have a structure like so:

index.php
core
  Exceptions
    ExceptionCore.php
    ExceptionUtil.php
Vendor
  autoload stuff

Index file:

<?php

require 'vendor/autoload.php';

new \core\Exceptions\ExceptionCore\ExceptionCore();

ExceptionCore:

<?php

Namespace core\Exceptions\ExceptionCore;

Class ExceptionCore
{
    public function __construct()
    {
        echo 'fffhf';
    }
}

But I am getting the error:

Fatal error: Uncaught Error: Class 'core\Exceptions\ExceptionCore\ExceptionCore' not found in C:\xampp\htdocs\user\index.php:5 Stack trace: #0 {main} thrown in C:\xampp\htdocs\user\index.php on line 5

Upvotes: 1

Views: 1594

Answers (2)

Semu
Semu

Reputation: 44

index file

<?php

require 'vendor/autoload.php';

new core\Exceptions\ExceptionCore\ExceptionCore(); // / delete

ExceptionCore:

Namespace core\Exceptions\ExceptionCore;

Class ExceptionCore
{
    public function __construct()
    {
        echo 'fffhf';
    }
}

code is work

Upvotes: 0

axiac
axiac

Reputation: 72177

The autoloader expects to find the class core\Exceptions\ExceptionCore\ExceptionCore in file core/Exceptions/ExceptionCore/ExceptionCore.php.

Read more about the PSR-0 and PRS-4 standards.

Upvotes: 2

Related Questions