Programming Articles

Page 1032 of 2547

PHP $argc

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 727 Views

The $argc variable is a PHP superglobal that stores the count of command−line arguments passed to a script. It is only available when running PHP scripts from the command line, not through a web server. The minimum value is 1 since the script filename itself counts as an argument. Note: This variable requires the register_argc_argv directive to be enabled in php.ini (enabled by default). Syntax The $argc variable is automatically populated when running PHP from command line ? Example Here's a script that validates the number of command−line arguments ...

Read More

PHP WeakReference class

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 544 Views

PHP's WeakReference class allows you to retain a reference to an object without preventing the garbage collector from destroying it. This is useful for implementing cache-like structures without memory issues, as the object can be freed when no strong references remain. What are Weak References? A weak reference differs from a normal reference because it doesn't prevent garbage collection. When all strong references to an object are removed, the object is immediately destroyed, even if weak references still exist. This enables efficient caching without memory leaks. Syntax WeakReference { /* Methods */ ...

Read More

PHP Traversable interface

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 532 Views

The Traversable interface is PHP's base interface for making objects work with foreach loops. It's an abstract interface that cannot be implemented directly − instead, you implement either Iterator or IteratorAggregate which extend Traversable. Syntax Traversable { // No methods - this is an abstract interface } Using IteratorAggregate The simplest way to make a class traversable is by implementing IteratorAggregate ? Apple Banana Cherry Using Iterator Interface For more control, implement the Iterator interface directly ? ...

Read More

PHP Throwable interface

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 596 Views

In PHP 7, the Throwable interface serves as the base interface for any object that can be thrown using the throw statement, including Error and Exception. Both Error and Exception classes implement this interface, making it possible to catch all throwable objects uniformly. Syntax Throwable { /* Methods */ abstract public getMessage ( void ) : string abstract public getCode ( void ) : int abstract public getFile ( void ) : string abstract public getLine ( ...

Read More

PHP Serializable interface

Malhar Lathkar
Malhar Lathkar
Updated on 15-Mar-2026 709 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
Malhar Lathkar
Updated on 15-Mar-2026 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
Malhar Lathkar
Updated on 15-Mar-2026 380 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
Malhar Lathkar
Updated on 15-Mar-2026 610 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
Malhar Lathkar
Updated on 15-Mar-2026 353 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
Malhar Lathkar
Updated on 15-Mar-2026 370 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
Showing 10311–10320 of 25,466 articles
Advertisements