Best practice for serving abstract class and subclasses?

I was wondering what is the best (and real) practice for creating an abstract class and subclasses in PHP when it comes to filing.

I have an abstract class games , and I was wondering if subclasses should be placed in separate files and require_once('games.class.php'); for individual files or just have each subclass in an abstract class games file?

Thanks!

+6
php
source share
3 answers

Usually people usually use a single file in a class - matching file names with class names (this makes it easier to autoload a>).


For a good example, you should take a look at the sources of the Zend Framework : there are a great number of classes, interfaces, abstract classes, multi-level subdirectories and all.

And here is the relevant part of their Coding Standards .

+8
source share

I would suggest using autoload instead of require or include, and of course, one file for each class.

0
source share

you are doing this in a more secure future, you are definitely sticking to "one class for each file."

Actual classes can then be included in many ways, including autoloader. One tip: just specify the file / class name:

 abstract class GamesAbstract {} 
 class Games extends GamesAbstract {} 
0
source share

All Articles