Johan Broddfelt

How to use classes

Now it is time to uncomment our File::getFileVersion() for main.css and main.js. So let's start by adding a folder called classes and create the file File.php with a capital F.

Now we have a class called File and it contains a function called getFileVersion. But we can not access it yet. We need to include it into our main_template.php. We could do that my adding the line require_once('classes/File.php');. And that is often used in other languages and give you a quick overview of what classes are used. But I want to write as few lines of code as possible and php offers a function called __autoload() that automatically includes the class file we needed. We will add that function into our global.php as follows.

Now we can uncomment the two lines in our main_template.php


and