One of the most important aspects of programming is design. Although a poorly designed program may function fine at first, after a while when the website needs to be upgraded, the time it will take to make minor updates could have been used to rewrite the entire application. Abstraction and decoupling are the two idea's we have to keep in mind if we want to create a well designed application. Although it is not necessary, more times than not, an Object Oriented Application [OOP] has a better design that most other types of code. For this reason, it will introduce to you the basics of OOP.
The first thing you need to do is create a class. The class header contains the key word class, followed by the name of the class, followed by an open brace. The footer contains the closing brace.
All the content of the class goes between the two braces. The next most important part of a class is the constructor. The constructor is the first method invoked when the class is instantiated. In PHP < 5 the constructor was declared as follows:Code:class HelloWorld {
}
And even in PHP 5.x that is acceptable, however PHP 5 has adopted a new convention, and since php 4.x is no longer supported, all my code will be PHP 5 oriented. The proper contention for PHP 5 is as follows:Code:function HelloWorld() {
}
That is , two underscores followed by the word construct. Now you can simply add your PHP code you wanted executed at run time in the constructor.Code:function __construct() {
}
The final class might look like this:Code:function __construct() {
echo "Hello World";
}
Code:class HelloWorld {
function __construct() {
echo "Hello World";
}
}
brief of Exception, the exception is most important part of OOP concept, cause with exception, your software will be flexible, and easy to manipulate when the unwanted/wanted action such error, etc
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks