PHP 6
PHP 6
PHP 6.0 is, in many ways, a “cleanup” release for the language. In addition to cleaning up the object model and fixing many bugs, PHP 6.0 adds full Unicode support from the ground up. It introduces large integers (64-bit) and better SQL Lite functionality, and includes all of the changes from PHP 5.1 through the final releases of the 5.0 line, as well as everything new in 6.0. Finally, PHP 6.0 gives us a true Unicodebasedlanguage for the first time in the history of scripting languages for the Net.

Understanding OOP Concepts

This section introduces the primary concepts of object - oriented programming and explores how they interact; Chapter 3 looks at the specifics of implementing them in PHP6. This chapters covers the following topics: Classes — The “ blueprints ” for an object and the actual code that defines the properties and methods Objects — Running instances of a class that contain all the internal data and state information needed for your application to function Inheritance — The ability to define a class of one kind as being a subtype of a different kind of class (much the same way a square is a kind of rectangle) Interfaces — A way of specifying that an object is capable of doing something without actually defining how it is to be done (e.g., a dog and a human are “ things that walk, ” but they do it very differently) Encapsulation — The ability of an object to protect access to its internal data Polymorphism — Allows a class to be defined as being a member of more than one category of classes (just as a car is “ a thing with an engine ” and “ a thing with wheels ” )

Classes :

In the real world, objects have characteristics and behaviors. A car has a color, a weight, a manufacturer, and a gas tank of a certain volume. Those are its characteristics. A car can accelerate, stop, signal for a turn, and sound the horn. Those are its behaviors. Those characteristics and behaviors are common to all cars. Although two particular cars in the same parking lot may have different colors, all cars have a color. Using a construct known as a class, OOP enables you to establish the idea of a car as being something with all those characteristics. A class is a unit of code (composed of variables and functions) that describes the characteristics and behaviors of all the members of a set. A class called Car would describe the properties and methods common to all cars. In OO terminology, the characteristics of a class are known as its properties . Properties have a name and a value. Some allow their value to be changed; others do not. For example, in the Car class, you would probably have such properties as color and weight . Although the color of the car can be changed by giving it a new paint job, the tare weight of the car (without cargo or passengers) is a fixed value. Some properties represent the state of the object. State refers to those characteristics that change because of certain events but are not necessarily directly modifiable on their own. In an application that simulates vehicle performance, the Car class might have a property called velocity . The velocity of the car is not a value that can be changed on its own, but rather is a by - product of the amount of fuel being sent to the engine, the performance characteristics of that engine, and the terrain over which the car is traveling. The behaviors of a class are known as its methods . Methods of classes are syntactically equivalent to functions found in traditional procedural code. Just like functions, methods can accept any number of parameters, each of any valid data type. Some methods act on external data passed to them as parameters, but they can also act on the properties of their object, either using those properties to inform actions made by the method (such as when a method called accelerate examines the remaining amount of fuel to determine whether the car is capable of accelerating) or to change the state of the object by modifying values such as the velocity of the car.

Objects :

To begin with, you can think of a class as a blueprint for constructing an object. In much the same way that many houses can be built from the same blueprint, you can build multiple instances of an object from its class; but the blueprint doesn ’ t specify details such as the color of the walls or the type of flooring. It merely specifies that those things will exist. Classes work much the same way. The class specifies the behaviors and characteristics the object will have, but not necessarily the values of those characteristics. An object is a concrete entity constructed using the blueprint provided by a class. The idea of a house is analogous to a class. Your house (a specific instance of the idea of a house) is analogous to an object. With a blueprint in hand and some building materials, you can construct a house. In OOP, when you use the class to build an object, this process is known as instantiation . Instantiating an object requires two things: A memory location into which to load the object. This is automatically handled for you by PHP. The data that will populate the values of the properties. This data can come from a database, a flat text file, another object, or some other source. A class can never have property values or state. Only objects can. You must use the blueprint to build the house before you can give it wallpaper or vinyl siding. Similarly, you must instantiate an object from the class before you can interact with its properties or invoke its methods. Classes are manipulated at design time when you make changes to the methods or properties. Objects are manipulated at run - time when values are assigned to their properties, and their methods are invoked. The problem of when to use the word class and when to use the word object is something that often confuses those new to OOP. After an object is instantiated, it can be put to work implementing the business requirements of the application. Let ’ s look at exactly how to do that in PHP.

Leave a Reply

Your email address will not be published. Required fields are marked *