This is for my DB class. I am new to OO, been a procedural lad for some time, so I’m still a bit murky.
My first idea was using a bunch of setter functions/methods.. but after writing a whole bunch, I thought about using PHP’s define function, like so.
define('MYSQL_USERNAME', 'jimbo');
Is this an accepted practice? What is the best practice? Should I really clutter my class with a bunch of setter functions (I am currently the only developer using these classes). What are your solutions?
Thank you!
I use
constonly for creating mnemonic names for immutable constants in the class. Thedefine()function does not create constants as part of the class, it creates constants in the global space.Class configuration data I usually declare as a
protectedhash-array in the class. Keys are useful for mnemonics. Values are defaults.Then I load an ‘ini’ format file with
parse_ini_file()and usearray_merge()to map the keys into your class config array: