There are some important things that we need to be aware of, before we start
building and using classes. We'll start by looking some naming conventions.
Class names should start with an uppercase letter.
All named elements should use the camelCase standard.
Method names should start with a lowercase letter.
Non-public elements should start with an underscore.
As only PHP 5 and above support access modifiers, we use a special naming
convention to indicate non-public elements. Methods and properties that are
non-public are prefixed with an underscore.
We often pass and return objects and arrays by reference. Doing this means that
multiple variables can 'point' to the same object or array. Note that in PHP 5 objects
are always passed by reference. Methods, functions, and parameters that return and
are passed by reference are prefixed with an ampersand. When we use a method
or function that returns a reference, we must use the &= assignment operator as the
following example demonstrates:
function &go()
{
$instance = new stdClass();
return $instance;
}
$reference =& go();
When we pass objects around we must bear in mind that PHP versions 5 and above
handle objects differently.
Pages:
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48