What is a class?

A class is just a normal PHP class. It doesn't need to extend anything or follow any conventions.

class Files {}

Creating classes

In order to function, a class must do the following:

  • Reside in "application/core" folder (or a sub-folder).
  • File name must match the class name exactly, e.g. session.php
  • The class name must map to the file name (with / replaced with _) and each word is capitalized.
  • All methods in a class must be static.

Some examples of class names and file locations:

// application/core/foobar.php
class Foobar {
// application/core/files.php
class Files {

Classes can be in sub-folders:

// application/core/foo/bar.php
class Foo_Bar {
// application/core/cache/files.php
class Cache_Files {

Loading classes

Class will be loaded by the system automatically whenever you access it. The following will load "files" class and execute "write" method:

files::write('my_file.txt', 'sample text');

Note that all methods in a class must be static:

class files
	public static function write($file, $text)
		file_put_contents($file, $content);

Core classes

There are several core classes that are included as part of the core framework. These classes are located in the "system/core" folder. They can be accessed the same way as in the example above.

Extending core classes

It is possible to extend core classes by creating files with the same name and placing them in the "application/core" folder. For example to extend "Session" class, we would create a file called "session.php" in that folder and place the following code in it (notice the name of the class we extend):

class Session extends CodeBreeder_Session
	public static function my_method()
		echo "example method";