 |
functions, classes, and objects -- oh my! by: misterhaan |
Page: 5 of 5 (View All) |
terms and comparisons
we'll start out with a review of the terms that came up:
class - a collection of variables and / or functions
constructor - the special function that a class may have, which is executed when an object is created from that class; the constructor must have the same name as the class
member - member variables and member functions are variables and functions that are defined inside of a class
object - an instance of a class; a variable created from a class that then gains the properties defined in the class; an object reference uses ->
oop - object-oriented programming; programming based on objects
static - static references use the name of the class and do not require an object to be created; a static reference uses ::
php uses the same syntax for classes and objects as c++ does, in that
static functions are accessed by classname::functionname and object
functions are accessed by objectname->functionname. some other
languages (java for example) use classname.functionname and
objectname.functionname instead. both c++ and java allow for parts
of the class to be defined as private, which means that you absolutely
cannot access those parts of the class from outside the class -- php
does not currently support this. java also requires that static
functions be specifically defined as static (c++ may support this as
well) -- php will let you call any function statically or from an object
(though it may not work!). very generally, php supports the use of
objects and classes, but it is not at all strict in its implementation.
to wrap things up, I'll show you a more complete example, which is my
(somewhat) current FORM class:
No Comments for this page.
|