You are here: Re: [PHP] functions vs classes « PHP « IT news, forums, messages
Re: [PHP] functions vs classes

Posted by Brent Baisley on 04/04/05 16:44

At the most basic level a class allows you to group your functions
together. On small projects, grouping of functions may not seem to buy
you anything. But the bigger the project gets, the more you would like
to be able to keep your functions separated into groups.

One simple advantage of classes is that they prevent naming conflicts
with your functions. This is very important when you are sharing code
since you don't know what another programmer named their functions.
What if you both name a function "get_one_record"? If you use classes,
you only need to keep the names of your classes unique. Which then
means you can use the same generic function name across all your
classes, and you interface within your classes in a consistent manner,
only the context changes.

For instance, you may have a class call "companies" and another called
"contacts". Within each you may have functions called "get_list",
"get_one" and "delete_one". Same function names, but in different
classes so they don't conflict. Now you could create a generic
interface to view a list, view a record or delete a record. What data
is displayed depends on which class you load. The function names are
all the same, so you don't need to change your code when you change the
context (companies or contacts).

This is hardly a tutorial on OOP. But maybe it will give you an idea of
the benefits of using classes.


On Apr 4, 2005, at 12:28 AM, DuSTiN KRySaK wrote:

> Novice PHPer, and i am wondering why one would use a function instead
> of a class (or object)? They seem to server very similar in use.
>
> The way I see it, is a function if for repeated use in a project
> specific manner, where as a class could be used for many projects.
>
> is this correct?
>
> Although one could just include the function library in multiple
> projects.
>
> Thanks!
>
> Dustin
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация