PHP - Ds\Pair::isEmpty() Function



The PHP Ds\Pair::isEmpty() function checks whether the pair is empty. The empty pair refers to a pair that does not contain any elements.

This function returns a boolean value 'true', if the current pair is empty, otherwise it will return 'false'.

The isEmpty() function of the pair class is not available in the latest PHP version. Ensure that you have the appropriate version of PHP installed in your system, or else you will face some error-related issues.

Syntax

Following is the syntax of the PHP Ds\Pair::isEmpty() function −

public bool Ds\Pair::isEmpty( void )

Parameters

This function does not accept any parameter.

Return value

This function returns "true" if the pair is empty, or "false" otherwise.

Example

The following program demonstrates the usage of the PHP Ds\Pair::isEmpty() function −

<?php 
   $pair = new \Ds\Pair("TP", "Tutorialspoint"); 
   echo "The original pair elements are: \n";
   print_r($pair);
   $res = $pair->isEmpty();
   echo "\nIs the pair is empty? ".$res;
?>

Output

Since this function is not available in the latest PHP version, it will throw the following error −

The original pair elements are:
Ds\Pair Object
(
    [key] => TP
    [value] => Tutorialspoint
)
PHP Fatal error:  Uncaught Error: Call to undefined method Ds\Pair::isEmpty() 
in C:\Apache24\htdocs\index.php:5
Stack trace:
#0 {main}
  thrown in C:\Apache24\htdocs\index.php on line 5
php_function_reference.htm
Advertisements