Lập trình hướng đối tượng với PHP5 pot

268 398 0
Lập trình hướng đối tượng với PHP5 pot

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

[...]... completely new object models and released PHP5 Now there are two versions of PHP being developed Don't get confused by comparing PHP versions with other languages PHP5 doesn't mean it is the latest PHP version As I said a while ago, PHP4 and PHP5 are being released actively (though there will be no more releases of PHP4 after December 2007) Between these two, PHP5 implements almost complete OO features... www.wordpress.org which is "Coding is poetry" Coding is exactly a poem; if you just know how to write it [ 14 ] Chapter 1 Difference of OOP in PHP4 and PHP5 Objects in PHP5 differ a lot from objects in PHP4 OOP became matured enough in true sense from PHP5 OOP was introduced since PHP3 but that was just an illusion for real object oriented programming In PHP4 you can create objects but you can't feel... There is no exception object in PHP4 But in PHP5 exception management is a great added feature There were some functions to investigate methods and properties of a class in PHP4, but in PHP5 beside those functions, a powerful set of API (Reflection API) is introduced for this purpose Method overloading via magic methods like get() and set() are available in PHP5 There are also���������������������������������������������������... internet is for free Please go to http://www.php.net and download the manual and read the basic chapters For a detailed learning of PHP, you can study the book Learning PHP5 written by David Sklar Ready, Set, Go In this book, we are using PHP5. 1.2 for our examples but for almost 99% of cases it will run with PHP version 5x We have MySQL 5 in our machine and Apache 2 as our web server If you aren't familiar... and extend all these methods defined in that abstract class A final class is an object which you are not allowed to extend In PHP5 you can use all of these In PHP4 there are no multiple inheritances for interfaces That means an interface can extend only one interface But in PHP5 multiple inheritance is supported via implementing multiple interfaces together In PHP4, almost everything is static That... Procedural Programming However it is not valid in PHP5 because the method echosomething() uses $this keyword which is not available in a static call There is no class-based constant in PHP4 There is no static property in objects in PHP4, and there is no destructor in PHP4 objects Whenever an object is copied, it is a shallow copy of that object But in PHP5 shallow copy is possible only using the clone... features while PHP4 doesn't At the time of writing this book the latest version of these two streams are PHP5. 2 and PHP4.4 [ 10 ] Chapter 1 Procedural vs OO Coding Style PHP allows you to write code in two flavours, one is procedural and the other is object oriented You can even write procedural code in PHP5 and it will run without any problems If you are not clear about procedural and object oriented programming,... = new emailer(); ?> When you execute the above code, it shows the warning as follows: Warning: Missing argument 1 for emailer:: construct(), called in C:\OOP with PHP5\ Codes\ch1\class.emailer.php on line 42 and defined in C:\OOP with PHP5\ Codes\ch1\class.emailer.php on line 9 See the difference? If your class had no constructor method or a constructor with no arguments, you can... coupling later in this book and understand how they will be useful for us Let's see the code of an object in PHP The following object is a very simple object which can send email to a bunch of users In PHP5, objects are a lot more different than an object in PHP4 We will not discuss the details of it, this is just an introductory object to see how the objects are written in PHP . Programming with PHP5 Learn to leverage PHP5& apos;s OOP features to write manageable applications with ease Hasin Hayder BIRMINGHAM - MUMBAI Object-Oriented Programming with PHP5 Copyright ©. vs. OO Coding Style 7 Benefits of OOP 8 Dissection of an Object 9 Difference of OOP in PHP4 and PHP5 11 Some Basic OO Terms 12 General Coding Conventions 13 Summary 14 Chapter 2: Kick-Starting. two very important features of object-oriented programming in PHP, reection and unit testing. PHP5 replaces many old APIs with smarter new ones. One of these is the Reection API, with which

Ngày đăng: 06/08/2014, 10:20

Mục lục

  • Object-Oriented Programming with PHP5

    • Table of Contents

    • Chapter 1: OOP vs. Procedural Programming

      • Introduction to PHP

      • A Little History of OOP in PHP

      • Dissection of an Object

      • Difference of OOP in PHP4 and PHP5

      • Some Basic OO Terms

      • Chapter 2: Kick-Starting OOP

        • Let's Bake Some Objects

          • Accessing Properties and Methods from Inside the Class

          • Extending a Class [Inheritance]

            • Overriding Methods

            • Static Method and Properties

            • Using Magic Methods to Set/Get Class Properties

            • Magic Methods for Overloading Class Methods

            • Visually Representing a Class

            • Chapter 3: More OOP

              • Class Information Functions

                • Checking if a Class Already Exists

                • Finding Currently Loaded Classes

                • Finding out if Methods and Properties Exists

                • Checking the Type of Class

                • Finding Out the Class Name

                • Exception Handling

                  • Collecting all PHP Errors as Exception

                  • Accessing Objects in Array Style

                  • Serialization

                    • Magic Methods in Serialization

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan