Jump to content

Class Constant vs. Class Methods


Man In Tan

Recommended Posts

This isn't really an important question, but since I've been going through my forum, optimizing as much as I can, I thought I might as well ask. I've already gone through and removed all double-quoted strings, almost all redirects, et cetera, so I'm working with the lesser details now.I have several object classes used to store different types of data in a flat file database. I have eleven, actually. Ten of the classes are extended from the eleventh class. Each class has a save_obj() method, to insure that all objects get saved to the correct files. Right now, the save_obj() method uses the static::type constant to determine the directory the file should be saved to. However, since I have to redefine that constant when I extend the class, I was wondering if it might be a good idea to just redefine the method to save to the correct directory, and remove the constant altogether.Obviously both work, but which format would be the better option?

<?php namespace us_0gb;/** * (c) Zero GigaBytes * ..... other documentation here ....**/class catfor {const type = 'catfor';final public function save_obj() {$data = \serialize($this);\file_put_contents(\us_0gb\FFF::$database.'/'.static::type.'/'.$this->_.'.txt', $data);} }class group extends \us_0gb\catfor {const type = 'group';}//And the file continues .....

<?php namespace us_0gb;/** * (c) Zero GigaBytes * ..... other documentation here ....**/class catfor {public function save_obj() {$data = \serialize($this);\file_put_contents(\us_0gb\FFF::$database.'/catfor/'.$this->_.'.txt', $data);} }class group extends \us_0gb\catfor {public function save_obj() {$data = \serialize($this);\file_put_contents(\us_0gb\FFF::$database.'/group/'.$this->_.'.txt', $data);} }//And the file continues .....

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...