View Single Post
Old 12-04-2008   #3
xcoder
Ma ghayro
 
xcoder's Avatar
 
Last Online: 04-19-2018
Join Date: Dec 2005
Posts: 5,592
Thanks: 1,765
Thanked 4,201 Times in 2,361 Posts
Groans: 12
Groaned at 18 Times in 11 Posts
Default Re: PHP5 OOP or Procedural

Thanks for your reply icemaker,
Indeed, that's what i think 2.
For example i am working on a BIG project currently and i have 2 tables for users the first one for managers who work in the control panel and the second one for public users who register on the website to have access to some utilities.

In the procedural way you will have to write the code twice for user registration once in the control panel and the second one on the public page which is not the case in OOP.

I simply created a rich featured users class and use it whenever i need.
In case i had more fields in the managers table let's say i can simply extend the class to inherit all (public,protected) methods and data members in the parent class and add the new ones.

a small basic example:
Code:
$manager=new User;
$manager->setUser($user);
$manager->setPass($pass);
if($manager->login()){
  $manager->updateLastLogin();
  $manager->createSession($manager::getSessName());
  header("location: index.php");
}else{
  $manager->updateLoginFailure();
  $manager->lastLoginAttempt();
  $manager->genError();
  login_form();
}
See how clear and clean the code is.
I am so excited about OOP, i m spending long hours coding daily.
Seeing the difference between php4 and php5 makes me wonder what would php6 be hiding.
__________________
http://twitter.com/danymoussa
xcoder is offline   Reply With Quote