Change language

PHP SplObjectStorage attach () function

Syntax:
void SplObjectStorage::attach ($obj, $val)
Parameters:This function takes two parameters, mentioned above and described below.
  • $obj:This is a required parameter that specifies the object of the storage class.
  • $val:this is an optional parameter that specifies the values ​​to be added.
Return value:This function does not return no value.The programs below illustrate the function SplObjectStorage::attach()in PHP:Program 1:  
// Declare a new object $obj = new StdClass;  
// Create empty storage class $str = new SplObjectStorage();  
// Append $obj with the string "GeeksforGeeks" $str -> attach ( $obj , "GeeksforGeeks" );  
// Print the result var_dump ( $str [ $obj ]);  
?>
Exit:
string (13 ) "GeeksforGeeks"
Program 2:  
// Create standard classes $obj1 = new StdClass; $obj2 = new StdClass; $obj3 = new StdClass; $obj4 = new StdClass; $str = new SplObjectStorage(); $str -> attach ( $obj1 ); $str -> attach ( $obj2 , "GFG" );  
// Another way to use the attach() function $str [ $obj3 ] = "GeeksforGeeks" ; $str [ $obj4 ] = NULL;  
// Print the result var_dump ( $str [ $obj1 ]); var_dump ( $str [ $obj2 ]); var_dump ( $str [ $obj3 ]); var_dump ( $str [ $obj4 ]);  
?>
Exit:
NULL string ( 3) "GFG" string (13) "GeeksforGeeks" NULL
Link: https://www.php.net/manual/en/splobjectstorage.attach.php

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method