Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 12-13-2011, 11:51 AM php classes
Extreme Talker

Posts: 176
Trades: 0
okay so I'm still figuring out classes

I read this tutorial which sort of explained it http://www.phpbuilder.com/columns/rod19990601.php3

But I still don't know really when or why to use them.

I know how to do everything on here www.w3schools.com/php/default.asp

So say I was making a log in system for a website, when / what would I use classes for. Could someone just give me examples of the class name / description and when you would use it? I don't need actual code, I know how to program, just not why / when to use them.
Skeddles is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-13-2011, 01:05 PM Re: php classes
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,384
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
classes are best when you need "re-usable" code, and if know how, why or when to use OOP methods and properties you know how to use classes.
All that a class does, is encapsulate methods (sub routines and functions) and properties (constants or variables) into a "wrapper" with a name.

One use is if you are writing an application that can use different database servers, you could encapsulate all the MySQL code in one class, Access in another, MSSQL in a third class etc.
Then your app could check a configuration parameter and include the appropriate class/module.

All the property and method names are the same across all three classes, but the code will have the appropriate syntax for the DB server.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-13-2011, 01:56 PM Re: php classes
Extreme Talker

Posts: 176
Trades: 0
Quote:
Originally Posted by chrishirst View Post
classes are best when you need "re-usable" code, and if know how, why or when to use OOP methods and properties you know how to use classes.
All that a class does, is encapsulate methods (sub routines and functions) and properties (constants or variables) into a "wrapper" with a name.

One use is if you are writing an application that can use different database servers, you could encapsulate all the MySQL code in one class, Access in another, MSSQL in a third class etc.
Then your app could check a configuration parameter and include the appropriate class/module.

All the property and method names are the same across all three classes, but the code will have the appropriate syntax for the DB server.
Well say my site is just adding / reading a database, would I ever use classes?
Skeddles is offline
Reply With Quote
View Public Profile
 
Old 12-13-2011, 02:24 PM Re: php classes
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
There are no specific circumstances in PHP where you must or even should use OOP.

Quote:
Originally Posted by Skeddles View Post
Well say my site is just adding / reading a database, would I ever use classes?
You could. You might have a database class that handles all of your queries.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 12-14-2011, 10:28 AM Re: php classes
Physicsguy's Avatar
404 - Title not found

Posts: 920
Name: Scott Kaye
Location: Ontario
Trades: 0
I usually use classes if I'm making something for somebody else, or if I'm building something massive that is hard to keep track of. However, I usually just write procedural code, as long as it's not repeated.

Seeing as you're making a site that will connect and read to a DB, you probably don't need a class. The same effect could be accomplished with a few lines of code:
1) connect to DB
2) read DB
3) echo contents of result-set
__________________
Check out my
Please login or register to view this content. Registration is FREE
or my
Please login or register to view this content. Registration is FREE
!

Last edited by Physicsguy; 12-14-2011 at 10:30 AM..
Physicsguy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to php classes
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29328 seconds with 12 queries