>Could someone please explain the difference between classes and functions
>and how to use a class. I write alot of PHP, but I never understood this at
>all. I use an include statement in many of my pages and include a file with
>a bunch of functions. For instance, I might have a function called stock();
>In the page I am using I include the file that has this function and I call
>it like this:
>I am wondering if I am doing it the wrong way. So I need to better
>understand classes. What is one, and why would you use it?

You can safely ignore classes for the rest of your PHP coding life. :-)

Classes are *MOST* useful when:

Multiple programmers are building a large application, and you want to force
some structure into that insanity.

You are creating a "library" to distribute, and you want to minimize the
number of functions/variables that might conflict with other people's source

You are modeling real-world objects with specific behaviours in your code.

The way you are doing it is *FINE*.

If you wanted to give away your stock() functions to everybody else, you
might want to create a class:

create class chris_cranes_stock_functions{
  function stock($sym = 'ZEND'){

Then, if the guy who uses your code already *HAS* a 'stock' function, yours
won't be in the way, because you've buried it inside your class.

But it's probably not going to magically increase the readability or
reliability of your code to just start throwing class objects in there for
the fun of it.

Your current usage of include/function is perfectly fine.

Like Music?  http://l-i-e.com/artists.htm

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to