Malhar Lathkar has Published 189 Articles

PHP Traversable interface

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 12:04:55

285 Views

IntroductionTraversable is an abstract interface, hence it can not be directly implemented by any class. Generally, Iterator or IteratorAggregate interfaces, which extend Traversable, are used to check if implementing class is traversable using foreach construct in PHP.Certain built-in classes that implement this interface can be used in foreach and need ... Read More

PHP Throwable interface

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 12:02:37

350 Views

IntroductionIn PHP 7, Throwable interface acts as base for any object that can be a parameter to throw statement, including Error and Exception. Both Error and Exception classes, from which predefined and user defined error and exception classes are derived respectively, implement Throwable interface. Following abstract methods are defined in ... Read More

PHP Serializable interface

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:51:42

374 Views

IntroductionThe Serializable interface is present in PHP library to build a class that provides custimised serialzing. PHP's serialize() function is able to serialize most of the values to a storable representation. However, objects of user defined classes can not be serialized. This interface makes it possible.SyntaxSerializable {    /* Methods ... Read More

PHP IteratorAggregate interface

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:49:43

324 Views

IntroductionIteratorAggregate interface extends abstract Traversable interface. It is implemented by a class to create external iterator. This interface introduces on abstract method called getIterator.SyntaxIteratorAggregate extends Traversable {    /* Methods */    abstract public getIterator ( void ) : Traversable }MethodsIteratorAggregate::getIterator — Retrieve an external iteratorThis function has no parameters and ... Read More

PHP Iterable interface

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:48:02

690 Views

IntroductionIterator interface extends abstract Traversable interface. PHP provides many built-in iterators (called SPL iterators) for many routine functionalities. Examples are ArrayIterator, DirectoryIterator etc. A user class that implements Iterator interface should implement abstract methods as defined in it.SyntaxIterator extends Traversable {    /* Methods */    abstract public current ( void ... Read More

PHP Generator class

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:45:54

567 Views

IntroductionTraversing a big collection of data using looping construct such as foreach would require large memory and considerable processing time. With generators it is possible to iterate over a set of data without these overheads. A generator function is similar to a normal function. However, instead of return statement in ... Read More

PHP Closure class

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:43:49

1K+ Views

IntroductionAnonymous functions (also called lambda) return object of Closure class. This class has some additional methods that provide further control over anonymous functions.SyntaxClosure {    /* Methods */    private __construct ( void )    public static bind ( Closure $closure , object $newthis [, mixed $newscope = "static" ] ... Read More

PHP ArrayAcccess interface

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:42:01

113 Views

IntroductionIn PHP, ArrayAccess interface is used to develop a class that provides array like access to one of properties which is an array. Such array property may be manipulated without exposing it during object creation. ArrayAccess interface defines following abstract methodsSyntaxArrayAccess {    /* Methods */    abstract public offsetExists ... Read More

PHP ArgumentCountError

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:37:53

366 Views

IntroductionPHP parser throws ArgumentCountError when arguments passed to a user defined function or method are less than those in its definition. ArgumentCountError class is inherited from TypeError classArgumentCountError ExampleIn Following example, a user defined function add() is defined to receive two arguments. However, if less than required number of arguments ... Read More

PHP ArithmeticError

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:34:49

149 Views

IntroductionArithmeticError class is inherited from Error class. This type of error may occurwhile performing certain mathemetical operations. One such scenario is attempt to perform bitwise shift operation by negative amount. This error is also thrown when call to intdiv() function results in value such that it is beyond legitimate boundaries of ... Read More

Advertisements