Coder Profile - Show off your skills, get a coder profile.
 
 
 
  
Posted: 179 Days Ago 

Dice
Australia
Contrib Level: 5
Total Posts: 163
Hey guys,

I've decided to learn OOP and what a better way then to write your own CMS. So anyways after some tutorials and playing around with OOP along with xdebug (most awesome debugging tool, honestly I only use it because the errors are colorful and aren't boring) I've come up with some code. This code checks the environment the php script is running in. Can you guys critique my OOP coding style? Thanks.

The Beloved Code:
CODE: index.php Copy / Restore  ::  Remove Scroll Bars
  1.  
  2. function __autoload($class_name) {
  3.     require_once 'lib/class.' . $class_name . '.php';
  4. }
  5.  
  6. $init = new init;
  7. $init->envCheck();
  8.  
  9. if ($init->getEnvErrors()) echo implode(',', $init->getEnvErrors());
  10.  
CODE: class.init.php Copy / Restore  ::  Remove Scroll Bars
  1.  
  2. class init {
  3.  
  4.     private $envErrors;
  5.  
  6.     public function envCheck () {
  7.         if (ini_get('register_globals') == 1) {
  8.             self::setEnvError('register_globals');
  9.         }
  10.  
  11.         if(get_magic_quotes_gpc()) {
  12.             self::setEnvError('magicquotes');
  13.         }
  14.     }
  15.  
  16.     private function setEnvError($error) {
  17.         $this->envErrors[] = $error;
  18.     }
  19.  
  20.     public function getEnvErrors() {
  21.         return $this->envErrors;
  22.     }
  23.  
  24. }
  25.  
Thanks guys
Posted: 154 Days Ago 

Helbom
Norway
Contrib Level: 1
Total Posts: 1
I'm not a guru in OOP, but from what I know, there's nothing wrong with the way you're doing this :)
Posted: 153 Days Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,709
Your better off starting with something simple... such as using proper objects... not init   

Example... a shopping cart...

A shopping cart contains items... which in turn must have a price, title and description... so... to enforce that using OOP you need the following:

An abstract class for the item... which contains the methods: get_price, get_description, get_title... then any item such as a book would extend the abstract item class... this then enforces that those methods exist.

Then you need a shopping cart class... this class needs a method like this: add_item(item $item);

Notice the type hint... this means that when an object is passed to the shopping cart, it will ONLY ACCEPT items that extend the abstract item class. This ensures it gets the correct items and it knows that those 3 methods exist: get_price, get_description, get_title.

Since the shopping cart uses the items... it should be done using aggregation because once you delete the shopping cart... then items should still exist   

I would write the code.... but really dont have the time.

Kind regards,
Scott
Page 1 of 1
 
 
Latest News About Coder Profile
Coder Profile Poll
If you made money from keeping your profile up to date, say $30 and up, per month. What extra time would you spend on your profile?

No extra time
A few hours at weekends
A whole day each week
Every minute i can get free


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
1.67 Year Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2010, Scott Thompson, All Rights Reserved