PHP Serializable interface

Malhar Lathkar
Updated on 15-Mar-2026 09:25:00

724 Views

The Serializable interface in PHP allows custom classes to define their own serialization behavior. While PHP's built-in serialize() function can handle most data types, objects of user-defined classes need this interface to control how they are converted to and from string representations. Syntax Serializable { /* Methods */ abstract public serialize() : string abstract public unserialize(string $serialized) : void } Methods Serializable::serialize() − Returns a string representation of the object Serializable::unserialize() − Reconstructs the object from its serialized string representation ... Read More

PHP Iterable interface

Malhar Lathkar
Updated on 15-Mar-2026 09:24:47

1K+ Views

The Iterator interface extends the abstract Traversable interface in PHP. It allows user-defined classes to become iterable using foreach loops. PHP provides many built-in iterators (called SPL iterators) like ArrayIterator, DirectoryIterator, etc. A user class implementing the Iterator interface must implement all its abstract methods. Syntax Iterator extends Traversable { /* Methods */ abstract public current ( void ) : mixed abstract public key ( void ) : scalar abstract public next ( void ) : void abstract public rewind ( void ... Read More

PHP ArrayAcccess interface

Malhar Lathkar
Updated on 15-Mar-2026 09:24:33

398 Views

In PHP, the ArrayAccess interface allows objects to be accessed like arrays using square bracket notation. When a class implements this interface, you can use $obj['key'] syntax to interact with the object's internal data without exposing the underlying array property directly. Syntax ArrayAccess { /* Methods */ abstract public offsetExists ( mixed $offset ) : bool abstract public offsetGet ( mixed $offset ) : mixed abstract public offsetSet ( mixed $offset , mixed $value ) : void ... Read More

PHP ArgumentCountError

Malhar Lathkar
Updated on 15-Mar-2026 09:24:16

639 Views

PHP throws ArgumentCountError when a function or method is called with fewer arguments than required in its definition. The ArgumentCountError class inherits from TypeError and can be caught using try-catch blocks. Basic Function Example Here's an example where a user-defined function add() expects two arguments but receives only one ? Too few arguments to function add(), 1 passed and exactly 2 expected Class Method Example ArgumentCountError also occurs with class methods when insufficient arguments are provided ? Too few arguments to function MyClass::setData(), ... Read More

PHP ArithmeticError

Malhar Lathkar
Updated on 15-Mar-2026 09:24:05

371 Views

The ArithmeticError class is inherited from the Error class. This type of error occurs while performing certain mathematical operations. One such scenario is attempting to perform a bitwise shift operation by a negative amount. This error is also thrown when a call to the intdiv() function results in a value that is beyond the legitimate boundaries of an integer. Bitwise Shift with Negative Number In the following example, an attempt is made to use the binary shift operator with a negative operand. This results in an ArithmeticError ? Bit shift by negative ... Read More

PHP AssertionError

Malhar Lathkar
Updated on 15-Mar-2026 09:23:56

383 Views

The AssertionError class is a subclass of the Error class in PHP. This exception is thrown when the assert() function evaluates to FALSE. The assert() function checks if a given assertion is true and throws an AssertionError if the condition fails. Syntax // PHP 5 and PHP 7 assert ( mixed $assertion [, string $description ] ) : bool // PHP 7 only assert ( mixed $assertion [, Throwable $exception ] ) : bool Parameters Parameter Description assertion String or boolean expression to evaluate description Failure message ... Read More

PHP CompileError

Malhar Lathkar
Updated on 15-Mar-2026 09:23:43

318 Views

In PHP 7.3 onwards, CompileError exception has been added. This class inherits the Error class. Some error conditions that previously resulted in fatal errors now throw a CompileError. This affects compilation errors that are likely to be thrown by the token_get_all() function when parsing invalid PHP syntax. The token_get_all() function uses Zend lexical scanner to parse a given string into PHP language tokens. When used in TOKEN_PARSE mode, it can throw a CompileError for invalid PHP code. Syntax token_get_all ( string $source [, int $flags = 0 ] ) : array Parameters ... Read More

PHP DivisionByZeroError

Malhar Lathkar
Updated on 15-Mar-2026 09:23:28

2K+ Views

The DivisionByZeroError class is a subclass of ArithmeticError class. This type of error occurs when division operations involve a denominator value of zero. This can also occur when a modulo operator (%) has 0 as the second operand, and the intdiv() function has 0 as its second argument. Modulo Division by Zero The modulo operator (%) throws a DivisionByZeroError when the divisor is zero ? Modulo by zero Integer Division by Zero The intdiv() function also raises DivisionByZeroError when the divisor is zero ? ... Read More

PHP ParseError

Malhar Lathkar
Updated on 15-Mar-2026 09:23:17

434 Views

ParseError class extends CompileError class and is thrown when PHP code inside a string passed to the eval() function contains syntax errors. The eval() function evaluates a given string as PHP code. If the code contains syntax errors, it throws a ParseError instead of causing a fatal error. Syntax eval ( string $code ) : mixed Parameters Parameter Description code Valid PHP code to be evaluated. Must not include opening/closing PHP tags and must end with semicolon. Valid code returns NULL, while syntax errors in the ... Read More

PHP Types of Errors

Malhar Lathkar
Updated on 15-Mar-2026 09:23:04

506 Views

PHP's internal Error types are represented by classes that are inherited from Error class. The Error class implements Throwable interface and provides a structured way to handle different types of runtime errors. Error Class Properties message − The error message code − The error code file − The filename where the error happened line − The line where the error happened Error Class Methods __construct() − Construct the error object getMessage() − Gets the error ... Read More

Advertisements