Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Designing Interfaces in PHP Introducing Interfaces Implementing an Interface

Implementing an Interface

Hey ya'll,

I'm stuck up a creek without a paddle. I have reviewed the code and all looks well, but I get this:

PHP Fatal error: Interface 'RepositoryInterface' not found in /home/treehouse/workspace/src/classes/jsonRepository.php on line 3

If you have some time to spare, I kindly ask that you preview my snapshot

Woke up today with this on my mind and with a few moments to share learned that in the config.php file, when I remove the final line that instantiates the $repo class, no error occurs, so at the moment I am led to believe that

$repo = new jsonRepository(__DIR__ . '/database.json'); 

is the issue~

Hey MM - It looks like in your autoloader you are breaking the loop once you find the first class? Maybe try looping through everything and try again?

<?php
// AUTOLOAD "REGISTRATION" FUNCTION
/* Autoload Function = Never Load a Class Again! */
function autoloader($class_name)
{
    /* Loop through '/src' DIR in Search of File */
    foreach (glob(__DIR__ . '/*', GLOB_ONLYDIR) as $dir) {
        if (file_exists("$dir/" . $class_name . '.php')) {
            /*Require File 'once' IF Exists*/
            require_once "$dir/" . $class_name . '.php';
            /* Stop Loop 'after' File has been found */

            /* Try commenting this out */
            break;
        }
    }
}

// REGISTER 'autoload' FUNCTION
spl_autoload_register('autoloader');

// INSTANTIATE CLASS
/* PASS jsonRepository.php File through Current Directory */
$repo = new jsonRepository(__DIR__ . '/database.json');
?>

2 Answers

Tried your suggestion @benpayne0925, to no avail. Nonetheless, I appreciate your support!

So...don't get too mad, but the RepositoryInterface in your snapshot is misspelled. See below:

<?php

interface RespositoryInterface { // RepositoryInterface is mispelled.
  /* Retrieve ALL Items */
  public function all($entity);
  /* Retrieve a Single-Item */
  public function find($entity, $id, $field = 'id');

}

?>

I removed the extra s and it seems to work now.

Cheers,

Ben

Thanks Ben. Not beating myself up; grateful you were here to assist! I owe you a beer~ hit me up if you are ever in (Louisville) Kentucky!