On Oct 11, 2007, at 8:36 AM, Jay Blanchard wrote:
[snip]
okay, this is really (!) embarassing, but I have to ask:
Why would I want to use classes in PHP?
I have been using PHP for years now and writing the "normal"
functions all
the time. I have never even bothered working with classes, but now
I would
love to know what makes the classes so special...
Please go easy on me ;o) Just trying to make another step :o)
[/snip]
Do not be embarrassed, this is a very good question.
First of all what you call "normal" is procedural or functional
programming. There is nothing wrong with doing things this way and
may be especially quick and efficient when doing basic web sites
and applications. Document well and you will have no problem
maintaining your code.
OOP (object oriented programming) is especially useful when the
application you have created needs to scale. A quick example; you
have sold your products to the consumer market for a long time but
now the commercial market has become interested. Commercial
customers are different than non-commercial customers, different
data, different credit requirements, different shipping, etc. but
they still have a lot in common, If you had a class Customer you
could extended that class to include commercial customers and only
have to code for the unique qualities of that kind of customer.
Then if another type of customer crops up, say a military contract,
you could extend again;
class Customer {
....
}
class CommercialCustomer extends Customer {
/*
*only code unique to commercial customers
* inherits from Customer other variables
* and functions that are common
*/
}
class MilitaryCustomer extends Customer {
/*
*only code unique to military customers
* inherits from Customer other variables
* and functions that are common
*/
}
http://www.sitepoint.com/article/object-oriented-php
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Not trying to hijack the thread... Hopefully this is related enough,
if not I apologize. Would a good use of a class be to write a generic
database connection script? and then feed in the different variables,
such as customer login, database, stuff like that?
something like class DBConnect {
// Connect to database
mysql_connect($server, $login, $password, $database);
}
or no?
--
Jason Pruim
Raoset Inc.
Technology Manager
MQC Specialist
3251 132nd ave
Holland, MI, 49424
www.raoset.com
japruim@xxxxxxxxxx
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php