Đang chuẩn bị liên kết để tải về tài liệu:
PHP 5 Recipes A Problem-Solution Approach 2005 phần 2

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Bài viết này cố gắng cung cấp cho bạn một cái nhìn tổng thể về những điểm cải tiến của PHP 5 trên các phương diện:tính năng ngôn ngữ, các phần mở rộng mới và những thay đổi đáng ghi nhận khác. | 2-3 SETTING OBJECT PROPERTIES 29 The output from this example is as follows Polynesia is a parrot and costs 15.00. Polynesia is a parrot and costs 54.95. Variations What happens if you change the line containing the call to the setPrice method to something like the following polly- setPice 54.95 Because you are attempting to call a method that has not been defined the result is an error message Fatal error Call to undefined method Bird setPice in home www php5 bird-5.php on line 22 You will probably agree that this makes it much easier to find the source of the problem. The same situation exists with regard to getting values of object properties if you ask PHP for the value of an undeclared variable the chances are good that you will obtain zero an empty string NULL or boolean FALSE. If this is the same as the property s default value or if the property has no default value then finding the source of the error can be particularly difficult. On the other hand defining and using a getPrice method minimizes the likelihood of such problems occurring. A construct such as this printf p s is a s and costs .2f. p n polly- getName polly- getBreed polly- getPrice may require a few extra keystrokes but you will find that the time saved in tracking down problems that do not give rise to any error messages is worth the effort. Note It is customary to name class members beginning with a lowercase letter. A possible exception to this is static members which we will talk about in recipe 2-5. As for what to do when a name contains more than one word two major schools of thought exist. Some programmers prefer to separate the words using underscores for example my_long_method_name . Others use what is known as intercap notation which consists of running the words together and capitalizing the first letter of each word after the first myLongMethodName .We prefer the latter so that is what we use. If you do not have to work to someone else s coding conventions then it is really just a