Re: [PHP] Classes - Dumb question



On Thursday 11 October 2007, 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.

One correction. What is being described is procedural or imperative
programming. Functional programming is another beast entirely (closures,
first-class functions, immutable variables, etc.). PHP is not a functional
language by any stretch of the imagination. For functional programming, see
Erlang, Haskel, ML, LISP, and to a lesser extent Javascript.

That's not a knock against PHP, mind you; I'm just pointing out that
functional programming is something different than what you are describing.
It's a common point of confusion because in a procedural language
(traditional PHP, C, etc.) you do everything with functions, so "it's
functional". The difference is that a function is not a base data type,
which is a key component of a functional language.

</semantic nitpick>

--
Larry Garfield AIM: LOLG42
larry@xxxxxxxxxxxxxxxx ICQ: 6817012

"If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an idea,
which an individual may exclusively possess as long as he keeps it to
himself; but the moment it is divulged, it forces itself into the possession
of every one, and the receiver cannot dispossess himself of it." -- Thomas
Jefferson
.



Relevant Pages

  • Re: [PHP] Classes - Dumb question
    ... Why would I want to use classes in PHP? ... Functional programming is another beast entirely (closures, ... Erlang, Haskel, ML, LISP, and to a lesser extent Javascript. ... It's a common point of confusion because in a procedural language ...
    (php.general)
  • Re: [PHP] What makes a PHP expert
    ... going with the grain of the language than when they are. ... other languages associative arrays are not as dead-easy as in PHP, ... including how many years a programmer had been using PHP. ... which an individual may exclusively possess as long as he keeps it to ...
    (php.general)
  • Re: Breaking backwards compatibility - good or bad?
    ... coming and are needed to anything really big and useful in PHP. ... command or statement in the language that is going to be made invalid ... The PHP team tries very hard not to break CORRECT scripts. ... "Introducing case-sensitivity for variables and functions names has ...
    (comp.lang.php)
  • Re: Case sensitivity in programming languages.
    ... the language. ... And these conventions take advantage of case sensitivity. ... In PHP it can be any of those things. ... group of programmers who want t force their stupid ideas onto others. ...
    (comp.lang.php)
  • Re: A Lot of Questions from a Noob
    ... OOP is a language paradigm that is not specific to ... I Google'd for an introduction to object-oriented programming, ... Watch out for the die-hard Perl fanbois: ... PHP 5 OOP has come a long way from PHP 4. ...
    (comp.lang.php)