Open In App

PHP SplObjectStorage offsetExists() Function

Last Updated : 23 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The SplObjectStorage::offsetExists() function is an inbuilt function in PHP which is used to check the object exist in storage or not.

Syntax: 

bool SplObjectStorage::offsetExists($object)

Parameters: This function accepts a single parameter $object which specifies the object to be checked.
Return Value: This function returns true if the object exists in storage otherwise return false.
Below programs illustrate the SplObjectStorage::offsetExists() function in PHP:

Program 1:  

php




<?php
  
// Create an empty SplObjectStorage
$str = new SplObjectStorage;
$obj = new StdClass;
  
// Attach $obj to $str 
$str->attach($obj);
  
// Print Result
var_dump($str->offsetExists($obj)); 
?>


Output: 

bool(true)

 

Program 2: 

php




<?php
  
// Create an Empty SplObjectStorage
$str = new SplObjectStorage();
   
$obj1 = new StdClass;
$obj2 = new StdClass;
$obj3 = new StdClass;
$obj4 = new StdClass;
  
// Attach only three objects
$str->attach($obj1, "GeksforGeeks");
$str->attach($obj2, "GFG");
$str->attach($obj3);
  
// Print result
var_dump($str->offsetExists($obj1)); 
var_dump($str->offsetExists($obj2)); 
var_dump($str->offsetExists($obj4)); 
var_dump($str->offsetExists($obj3)); 
  
?>


Output: 

bool(true)
bool(true)
bool(false)
bool(true)

 

Reference: https://www.php.net/manual/en/splobjectstorage.offsetexists.php



Similar Reads

ArrayObject offsetExists() Function in PHP
The offsetExists() function of the ArrayObject class in PHP is used to whether a given offset or index is present in the ArrayObject or not. If it is present then the function returns a boolean True value otherwise it returns False. Syntax: bool offsetExists($index) Parameters: This function accepts a single parameter $index which is the index whic
2 min read
PHP SplDoublyLinkedList offsetExists() Function
The SplDoublyLinkedList::offsetExists() function is an inbuilt function in PHP which is used to check whether the given index exists or not. Syntax: bool SplDoublyLinkedList::offsetExists( $index ) Parameters: This function accepts a single parameter $index which holds the index value to be checked. Return Value: It returns True if given index exis
1 min read
PHP SplFixedArray offsetExists() Function
The SplFixedArray::offsetExists() function is an inbuilt function in PHP which is used to check provided index exist or not in an array. Syntax: bool SplFixedArray::offsetExists( $index ) Parameters: This function accepts single parameter $index which specifies the requested index. Return Value: This function returns true if requested index found o
1 min read
PHP | ArrayIterator offsetExists() Function
The ArrayIterator::offsetExists() function is an inbuilt function in PHP which is used to check the existence of offset at the given index. Syntax: bool ArrayIterator::offsetExists( mixed $index ) Parameters: This function accepts single parameter $index which holds the index value to check the existence of offset. Return Value: This function retur
2 min read
PHP SplObjectStorage contains() Function
The SplObjectStorage::contains() function is an inbuilt function in PHP which is used to check the storage object contains a specified object or not. Syntax: bool SplObjectStorage::contains( $value ) Parameters: This function accepts a single parameter $value which specifies the storage object which is going to check. Return Value: This function re
1 min read
PHP SplObjectStorage count() Function
The SplObjectStorage::count() function is an inbuilt function in PHP which is used to count the number of objects in storage. Syntax: int SplObjectStorage::count() Parameters: This function does not contains any parameter. Return Value: This function returns number of objects in storage. Below programs illustrate the SplObjectStorage::count() funct
1 min read
PHP SplObjectStorage addAll() Function
The SplObjectStorage::addAll() function is an inbuilt function in PHP which is used to add elements from another storage. Syntax: void SplObjectStorage::addAll( $value ) Parameters: This function accepts a single parameter $value which holds an storage which need to import. Return Value: It does not return any value. Below programs illustrate the S
1 min read
PHP SplObjectStorage valid() Function
The SplObjectStorage::valid() function is an inbuilt function in PHP which is used to check the current storage entry is valid or not. Syntax: bool SplObjectStorage::valid() Parameters: This function does not accept any parameter. Return Value: This function returns true if the iterator entry is valid, false otherwise. Below programs illustrate the
1 min read
PHP SplObjectStorage attach() Function
The SplObjectStorage::attach() function is an inbuilt function in PHP which is used to add objects into the SplObjectStorage. Syntax: void SplObjectStorage::attach($obj, $val) Parameters: This function accepts two parameters as mention above and described below. $obj: This is required parameter which specifies the object of the storage class. $val:
1 min read
PHP SplObjectStorage current() Function
The SplObjectStorage::current() function is an inbuilt function in PHP which is used get the current entry of storage. Syntax: object SplObjectStorage::current() Parameters: This function does not accept any parameter. Return Value: This function returns the object of the current storage. Below programs illustrate the SplObjectStorage::current() fu
1 min read