Page 179 - Open Soource Technologies 304.indd
P. 179
Unit 8: Objects
through user interfaces such as web pages, we can interact with them and make them perform Notes
tasks and procedures, as well as calculate, retrieve and modify properties.
PHP gives us a very simple way to define an object programmatically, and this is called a class.
A class is a wrapper that defines and encapsulates the object along with all of its methods and
properties. You can think of a class as a programmatic representation of an object, and it is
the interface that PHP has given you, the developer, to interact with and modify the object.
Moreover, a class may be re-used infinitely if need be, making it very powerful and codebase
friendly. You do not have to redefine things every time you want to use an object; a properly
coded class is set up to do all of the work.
Within the class wrapper, we can either define values of certain properties of the object, or tell
the object to do things. Therefore it is important at this point to realize that a class has two main
components: methods and properties. A method is essentially a function within a class, and a
class may contain no methods, or thousands of methods. Properties are exactly what they seem
to be; they are the properties of the object, and we usually use methods to set, modify and get
properties from an object.
Object handling was completely rewritten for PHP 5, expanding the feature
set and enhancing performance of PHP programming.
Self Assessment
Choose the correct answer:
1. Basic object-oriented programming functionality was added in PHP version is:
(a) 1 (b) 2
(c) 3 (d) 4
2. A ……………… consists of a member variable and methods.
(a) method (b) object
(c) property (d) class
3. Which one is not an access modifier?
(a) Public (b) Private
(c) Protected (d) Class
4. A class is a wrapper that defines and encapsulates the object along with all of its methods
and properties.
(a) True (b) False
8.2 Terminology
Every object-oriented language seems to have a different set of terminology for the same old
concepts. This describes the terms that PHP uses, but be warned that in other languages these
terms may have different meanings.
Let’s return to the example of the users of a bulletin board. You need to keep track of the same
information for each user, and the same functions can be called on each user’s data structure.
When you design the program, you decide the fields for each user and come up with the functions.
In OOP terms, you are designing the user class. A class is a template for building objects.
LOVELY PROFESSIONAL UNIVERSITY 173