Malhar Lathkar has Published 154 Articles

PHP IteratorAggregate interface

Malhar Lathkar

Malhar Lathkar

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

484 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

967 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

763 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

258 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

527 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

279 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

PHP AssertionError

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:32:36

287 Views

IntroductionAssertionError class is a subclass of Error class. This type of error is thrown when assert() returns FALSEassert() checks if given assertion is true or false, and throws AssertionError if it is false. The assert() function is defined as follows −Syntaxfor PHP 5 and PHP 7 assert ( mixed $assertion [, ... Read More

PHP CompileError

Malhar Lathkar

Malhar Lathkar

Updated on 21-Sep-2020 11:30:17

245 Views

IntroductionIn PHP 7.3 onwards, CompileError exception has been added. This class inherits Error class. Some error conditions that previously resulted in fatal error, now throw a CompileError. This affects compilation errors that are likely to be thrown by token_get_all() function.The token_get_all() function uses Zend lexical scanner to parse a given string ... Read More

PHP DivisionByZeroError

Malhar Lathkar

Malhar Lathkar

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

2K+ Views

IntroductionDivisionByZeroError class is a subclass of ArithmeticError class. This type of error occurs when division operation involves value of denominator as zero. This can also occur when a modulo operator (%) has 0 as second operator, and intdiv() function having second argument as 0.DivisionByZeroError ExampleIn first example, we try to perform modulo ... Read More

Advertisements