PHP Designing Interfaces in PHP Introducing Interfaces Autoloading

Error in the treehouse code!! I think this is a bug!

I keep getting this error:

Parse error: syntax error, unexpected '$title' (T_VARIABLE) in /home/treehouse/workspace/index.php on line 4

This is a line of code that came preloaded on the workspaces.

I've included all of the files worked with so far index.php

<?php

require_once"src/config.php"
//the line below is in question
$title = "My Website";

require 'views/header.php';

require 'views/footer.php';

config.php

<?php

function autoloader($class_name) {
  foreach(glob(__DIR__ . '*/', GLOB_ONLYDIR) as $dir) {
    if (file_exists("dir/" . $class_name . '.php')) {
        require_once "dir/" . $class_name . '.php':
        break;
    } 
  }
}

spl_autoload_register('autoloader');

Collection.php

<?php

class Collection {

}

2 Answers

Gregor Medvesek
Gregor Medvesek
16,461 Points

line 3 on index.php is missing a semicolon at the end

require_once "src/config.php";
Glenré Charl Labuschagné
Glenré Charl Labuschagné
23,155 Points

Hi annapoff,

In your src/config.php file your missing a $ before "dir/" variable…

          if (file_exists("$dir/" . $class_name . '.php')) {
            require_once "$dir/" . $class_name . '.php';
            break;
        }

Hope it helps