Autoload parent class from a different directory

I´m having a hard time trying to autoload parent classes

this is my directory structure

--- Homepage.php
--- Controller.php

This is the content of my index.php

function __autoload($class_name)
    $file_name = str_replace("", DIRECTORY_SEPARATOR, $class_name) . '.php';
    include $file_name;

$homepage = new ControllersHomepage();

This is the content of my controllers/Homepage.php file

namespace Controllers;

class Homepage extends Controller

    public function index()
        echo 'Homepage::index';


and this is my core/Controller.php

namespace Core;

class Controller

    protected function something()
        echo 'blablabla';


when i run index.php the autoloader loads Hompege correctly but is looking for Controller.php in the controllers directory I tried extending from class Homepage extends CoreController but now is trying to get it from controllers/core

Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.