2

My ./app folder looks like:

+-- app
   +-- Classes
       +-- Events
          +-- EventBase.php
          +-- EventX.php

There's nothing secret with EventX file:

<?

namespace App\Classes\Events;

class EventX {
  // ...
}

EventBase.php represents a Facade that inside it I just try to instantiate an EventX:

public function someMethod() {
  new \App\Classes\Events\EventX;
  // ...
}

After this line, Framework throw an exception telling that class was not found:

Symfony\Component\Debug\Exception\FatalThrowableError (E_ERROR)
Class 'App\Classes\Events\EventX' not found

Even that:

file_exists(__DIR__ . '\EventX.php'); // true

I already had this issue before when trying to create Facades and solved by moving class file from his current directory and after moving back (yeah, I don't why but it worked).

Something tells me that this is an issue of autoload process, so I tried these command (but still not working):

php artisan cache:clear

php artisan clear-compiled

php artisan config:clear

composer dump-autoload

What can I do in order to investigate the problem?

5
  • 1
    I'm not sure, but a leading `\` cause it perhaps? But, fyi, you can directly call the class without its namespace since it appears inside same directory. Commented Nov 28, 2017 at 12:11
  • @Chay22 I know and also tried that, this is not a namespace issue even because there's no complex structure. Seems like an autoload problem Commented Nov 28, 2017 at 12:15
  • Well, it's hard then. Have you tried to delete vendor directory and perform composer reinstall? Commented Nov 28, 2017 at 12:17
  • "\" can't cause it because it's just an absolute way to set the class namespace. \App\Classes\Events\EventX or EventX has same output in this case... Commented Nov 28, 2017 at 12:18
  • @Chay22 packages reinstalled but the problem still as before. Commented Nov 28, 2017 at 12:30

2 Answers 2

1

I think the problem is with the php tag <?

<?php

namespace App\Classes\Events;

class EventX {
  // ...
}

PHP also allows for short open tag <? (which is discouraged since it is only available if enabled using the short_open_tag php.ini configuration file directive, or if PHP was configured with the --enable-short-tags option).

Link

Sign up to request clarification or add additional context in comments.

Comments

0

You need to add the new namespace to your composer.json to the key "psr-4"

    "psr-4": {
        "App\\": "app/",
        "Classes\\": "app/classes/"

otherwise composer can't detect your new namespace

Another approach can be found here: https://stackoverflow.com/a/28360186/6111545

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.