TAILIEUCHUNG - Pro PHP Patterns, Frameworks, Testing and more phần 5

Thư viện chuẩn PHP (SPL) là nơi mà khả năng hướng đối tượng của PHP 5 thực sự tỏa sáng. Nó cải thiện ngôn ngữ trong năm cách quan trọng: vòng lặp, các ngoại lệ, mảng quá tải, XML, và tập tin và xử lý dữ liệu. Nó cũng cung cấp một vài mặt hàng khác hữu ích, | CHAPTER 9 Introduction to SPL The Standard PHP Library SPL is where PHP 5 s object-oriented capabilities truly shine. It improves the language in five key ways iterators exceptions array overloading XML and file and data handling. It also provides a few other useful items such as the observer pattern counting helper functions for object identification and iterator processing. Additionally it offers advanced functionality for autoloading classes and interfaces. This chapter introduces you to this very important library and in the following chapters you will learn more about some of the advanced SPL classes. SPL is enabled by default and is available on most PHP 5 systems. However because SPL s features were dramatically expanded with the PHP release I recommend using that version or newer if you want to truly take advantage of this library. SPL Fundamentals The SPL is a series of Zend Engine 2 additions internal classes and a set of PHP examples. At the engine level the SPL implements a set of six classes and interfaces that provide all the magic. These interfaces and the Exception class are special in that they are not really like a traditional interface. They have extra powers and allow the engine to hook into your code in a specific and special way. Here are brief descriptions of these elements ArrayAccess The ArrayAccess interface allows you to create classes that can be treated as arrays. This ability is commonly provided by indexers in other languages. Exception The Exception class was introduced in Chapter 4. The SPL extension contains a series of enhancements and classifications for this built-in class. Iterator The Iterator interface makes your objects work with looping structures like foreach. This interface requires you to implement a series of methods that define which entries exist and the order in which they should be retrieved. IteratorAggregate The IteratorAggregate interface takes the Iterator concept a bit further and allows you to offload the

Đã 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.