Question: What is full form of SPL?
Standard
PHP
Library.
Question: What is SPL?
It is collection of interfaces and Classes.
Question: Do we need to download library for SPL?
No, We need not to download external library.
Question: What does provide SPL?
SPL provides following Iterators, Interface and Functions.
- Set of standard Data Structure.
- a Iterators to traverse over objects
- Set of Interfaces
- Set of standard Exceptions
- SPL Functions
- SPL File Handling
Question: What classes are available in SPL data structure?
Doubly Linked Lists: It is a list of nodes linked in both directions to each other. Iterator operations, access to both end node, addition or removal of nodes.
http://php.net/manual/en/class.spldoublylinkedlist.php
Heaps: Heaps are tree-like structures that follow the General heap, each node is greater than or equal to its children.
http://php.net/manual/en/class.splheap.php
Arrays: Arrays are structures that store the data in a continuous way, accessible via indexes.
http://php.net/manual/en/class.splfixedarray.php
Map: A map is a datastructure holding key-value pairs. PHP arrays can be seen as maps from integers/strings to values.
http://php.net/manual/en/class.splobjectstorage.php
Question: What Iterators classes are available in SPL?
- AppendIterator
- ArrayIterator
- CachingIterator
- CallbackFilterIterator
- DirectoryIterator
- EmptyIterator
- FilesystemIterator
- FilterIterator
- GlobIterator
- InfiniteIterator
- IteratorIterator
- LimitIterator
- MultipleIterator
- NoRewindIterator
- ParentIterator
- RecursiveArrayIterator
- RecursiveCachingIterator
- RecursiveCallbackFilterIterator
- RecursiveDirectoryIterator
- RecursiveFilterIterator
- RecursiveIteratorIterator
- RecursiveRegexIterator
- RecursiveTreeIterator
- RegexIterator
Question: What Interfaces are available in SPL?
- Countable
- OuterIterator
- RecursiveIterator
- SeekableIterator
- SplObserver
- SplSubject
Question: What Exception classes are available in SPL?
- BadFunctionCallException
- BadMethodCallException
- DomainException
- InvalidArgumentException
- LengthException
- LogicException
- OutOfBoundsException
- OutOfRangeException
- OverflowException
- RangeException
- RuntimeException
- UnderflowException
- UnexpectedValueException
Question: What are the advantage of iterators?
- Laziness: the data is only fetched when you actually need it.
- Reduced memory usage: SPL iterators encapsulate the list and expose visibility to one element at a time making them far more efficient.
Question: Give an example of Iterating Arrayst?
$arr = array("One", "Two", "three", "Four", "Five", "Six");
$iter = new ArrayIterator($arr);
foreach ($iter as $key => $value) {
echo $key . ": " . $value ;
}
Output
0: One
1: Two
2: three
3: Four
4: Five
5: Six
Question: Give an example of Iterating Directory Listings?
$dir = new DirectoryIterator("/");
foreach ($dir as $item) {
echo $item . "
";
}
Output
$RECYCLE.BIN
Backup
banner
blog backup
data
data.log.txt
desktop files
doremon
mm
mongodb
Question: Give an example of Iterating Directory Recursively?
$iter = new RecursiveDirectoryIterator("/");
foreach (new RecursiveIteratorIterator($iter) as $item) {
echo $item . "
";
}