SPL是用於解決典型問題(standard problems)的一組接口與類的集合。
數據結構
SPL提供了一組標準數據結構。
雙向鏈表
雙向鏈表 (DLL) is a list of nodes linked in both directions to each others. Iterator's operations, access to both ends, addition or removal of nodes have a cost of O(1) when the underlying structure is a DLL. It hence provides a decent implementation for stacks and queues.
堆
Heaps are tree-like structures that follow the heap-property: each node is greater than or equal to its children, when compared using the implemented compare method which is global to the heap.
陣列
Arrays are structures that store the data in a continuous way, accessible via indexes. Don't confuse them with PHP arrays: PHP arrays are in fact implemented as ordered hashtables.
映射
A map is a datastructure holding key-value pairs. PHP arrays can be seen as maps from integers/strings to values. SPL provides a map from objects to data. This map can also be used as an object set.
迭代器
SPL 提供一系列迭代器以遍歷不同的對象。
- ArrayIterator
- EmptyIterator
- IteratorIterator
- MultipleIterator
- RecursiveIteratorIterator
- DirectoryIterator (extends SplFileInfo)
接口
SPL 提供一系列接口。
異常
SPL 提供一系列標準異常。
- LogicException (extends Exception)
- RuntimeException (extends Exception)
SPL函數
- class_implements — 返回指定的類實現的所有接口。
- class_parents — 返回指定類的父類。
- class_uses — Return the traits used by the given class
- iterator_apply — 爲迭代器中每個元素調用一個用戶自定義函數
- iterator_count — 計算迭代器中元素的個數
- iterator_to_array — 將迭代器中的元素拷貝到數組
- spl_autoload_call — 嘗試調用所有已註冊的__autoload()函數來裝載請求類
- spl_autoload_extensions — 註冊並返回spl_autoload函數使用的默認文件擴展名。
- spl_autoload_functions — 返回所有已註冊的__autoload()函數。
- spl_autoload_register — 註冊__autoload()函數
- spl_autoload_unregister — 註銷已註冊的__autoload()函數
- spl_autoload — __autoload()函數的默認實現
- spl_classes — 返回所有可用的SPL類
- spl_object_hash — 返回指定對象的hash id
文件處理
SPL 提供 一些與文件相關的類。