TAILIEUCHUNG - PHP 5 Recipes A Problem-Solution Approach PHẦN 5

Ví dụ, mỗi thể hiện của Parrot có một birdCall (). Bởi vì birdCall () là một phương pháp nào, bạn có thể định nghĩa lại nó trong Parrot mà không ảnh hưởng đến phương pháp birdCall () khi được gọi là một thể hiện của chim hoặc phân lớp khác. Đây là những gì chúng tôi có ý nghĩa trọng một phương pháp của một lớp cha mẹ. | 250 5-13 EXTENDING THE DATE CLASS Date is now Mon 26 Feb 2007 21 30 45 1000. Using the toString method on the same date yields 2007-02-26 21 30 45 10 00. Finally let s try some other ways to call the constructor. First the RFC-formatted date 24 Sept 2005 2005-09-24 00 00 00 10 00. And now we ll try it with xmas2k new Date 2000 11 25 followed by echo xmas2k- toLocaleString echo xmas2k- toUTCString Mon 25 Dec 2000 00 00 00 1000 Sun 24 Dec 2000 14 00 00 UTC Now for some UTC methods using xmas2k. Calling xmas2k- setUTCDate 30 UTC date Sat 30 Dec 2000 14 00 00 UTC local date Sun 31 Dec 2000 00 00 00 1000 Calling xmas2k- setUTCHours 48 UTC date Mon 01 Jan 2001 00 00 00 UTC local date Mon 1 Jan 2001 10 00 00 1000 Calling xmas2k- setUTCFullYear 2008 UTC date Tue 01 Jan 2008 00 00 00 UTC local date Tue 1 Jan 2008 10 00 00 1000 This may seem like a lot of work just to get and set dates but the payoff comes from having a clear and well-defined interface for dealing with a complex structure. However so far you are able to use this class to work with dates only as numbers or sets of numbers. What about being able to output dates in a more conventional format such as March 15 2005 8 25 . Do you have to sacrifice PHP s capabilities in this regard in order to have a nice programming construct The answer to this question is No you do not. As you saw in Chapter 2 it is possible to extend classes to provide additional functionality. This is exactly what you are going to do in the next example. 5-13. Extending the Date Class PHP s native date and time functions provide lots of output options which the Date class you developed in the previous section does not really let you take advantage of. You could go back and add new methods to that class to take care of this shortcoming but you do not really want to do this for a couple of reasons The Date class having more than two dozen methods is already fairly long and complex. Any advantage you might gain from adding methods to it is .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.