PHP | Predefined classes and Interfaces
Last Updated :
11 Jun, 2020
Improve
There are classes and interfaces that can be either user defined or pre-defines in PHP language.
There are 9 predefined classes and interfaces in PHP:
- Traversable
- Iterator
- IteratorAggregate
- Throwtable
- ArrayAccess
- Serializable
- Closure
- Generator
Method name | parameters | return value | description |
---|---|---|---|
current | void | mixed | The present value is returned. |
key | void | scalar | The present value's key is returned. |
next | void | void | Moving forward to the next element. |
rewind | void | void |
Set the position of the file pointer to the beginning of the file. |
valid | void | bool | Check whether an array contains more entries or not. |
method name | parameters | return type | description |
---|---|---|---|
getIterator | void | traversable | This function is used for retrieving an iterator(external). |
Throwtable
This feature is available in PHP version 7. All objects that are thrown through the throw statement has an interface which acts as base interface called Throwtable. Exception and Error classes use this interface.
Method name | number of arguments | name of arguments | return type | description |
---|---|---|---|---|
getMessage | 0 | void | string |
Returns the message to be displayed when exception occurs. |
getPrevious | 0 | void | throwtable | Previous exceptions are returned. |
getCode | 0 | void | mixed | The code for exception generated. |
getFile | 0 | void | string | The file in which exception occurs is returned. |
getLine | 0 | void | int | The line number in which exception occurs returned. |
getTrace | 0 | void | array | The stack trace is returned. |
getTraceAsString | 0 | void | string | The stack trace is returned in the form of string. |
__toString | 0 | void | string | The exception generated is returned in the form of string. |
method name | parameters | returns | description |
---|---|---|---|
offsetExists | offset value(mixed) | bool | Checks existence of the offset. |
offsetGet | offset value(mixed) | mixed | The offset is retrieved through this method. |
offsetSet | offset value(mixed), element(mixed) | void | A mentioned offset is given some value. |
offsetUnset | offset value(mixed) | void | The value of offset is unset. |
method name | parameters | return | description |
---|---|---|---|
serialize | void | string | Object is converted into string. |
unserialize | serialized string (string) | void | The object that was converted into string is converted back to an object. |
method name | parameters | returns | description |
---|---|---|---|
__construct | void | void | A constructor disallowing instantiation |
bind |
object (closure) newthis (object)closure | closure | A closure can be duplicated by the class scope and mentioned particular bound object. |
bindTo | newthis (object)closure | closure | A closure can be duplicated by the class scope and new bound object. |
call | newthis (object)closure | mixed | The closure is binded and called. |
fromCallable | Callable (Callable ) | closure | The callable is converted into closure. |
method name | parameters | returns | descitption |
---|---|---|---|
current | void | mixed | The yielded element can be found. |
getReturn | void | mixed | The generator's value is returned by the function. |
key | void | mixed | The key which was yielded is returned. |
next | void | void | The generator's execution is resumed. |
rewind | void | void | The iterator is rewinded. |
send | value(mixed) | mixed | A value is sent to the generator. |
throw | exception(throwtable) | mixed | An exception is thrown into the generator. |
valid | void | bool | Verifies if there was a closing of the iterator. |
__wakeup | void | void | Callback is serialized. |