NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP5 Static Classes

Jayesh Sheth jayeshsh at ceruleansky.com
Mon Mar 7 17:47:16 EST 2005


Hi Matt,

the following new book lists a lot of good reasons for using 
object-oriented programming with PHP:
PHP 5 Objects, Patterns, and Practice
http://apress.com/book/bookDisplay.html?bID=358

Even though this book is about how to use objects and patterns in PHP 5, 
the author explains on numerous occassions how the object-oriented 
version of something can save you from duplicating code, or improving 
the readability of your code.

With PHP you can put a functional / procedural interface on top 
instantiated objects, as you do not have to have a 'main' method as in 
Java. In other words:

require 'happy_funcs.php';
require 'moodBrightener.class.php';

$person = 'Fred';
if (  person_is_unhappy($person) )
{
    $mints = new moodBrightener('mints');
    $mints->makeHappy($person);
}

Often, it is not so much a matter of saving computer resources, but 
saving human resources. Some OOP techniques can help to ,modularize 
chunks of code, and establish relationships between them. And unlike 
functions, classes can 'borrow' or inherit functionality from other 
classes. So this saves you from copying and pasting code.

I hope this somewhat generalized example makes sense.

- Jay




More information about the talk mailing list