note 11973 deleted from function.unset by didou

From: Date: Tue, 19 Aug 2003 15:47:23 +0000
Subject: note 11973 deleted from function.unset by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-54690@lists.php.net to get a copy of this message
Note Submitter: nhanasoge@hotmail.com ---- Semi-equivalence between unset() and NULL.<br>There are some similarities and differences between using unset() and assigning NULL.<br> SIMILARITIES:<br> $myvar1 = 'Alpha'; unset($myvar1); $myvar2 = 'Bravo'; $myvar2 = NULL; // never defined $myvar3 Now all three -- $myvar1, $myvar2, and $myvar3 -- give identical results when tested with isset (FALSE in each case), empty (TRUE), var_dump (NULL), echo (nothing) and gettype (NULL). DIFFERENCES:<br> $myarray1 = array(); $myarray1['myelem1'] = 'Charlie'; // optional unset($myarray1['myelem1']); $myarray2 = array(); $myarray2['myelem2'] = 'Delta'; // optional $myarray2['myelem2'] = NULL; $myarray3 = array(); // never defined $myarray3['myelem3'] Now, the three array _elements_ $myarray1['myelem1'], $myarray2['myelem2'], $myarray3['myelem3'] give identical results as before. But the _arrays_ themselves give different results when tested with sizeof (arrays 1 and 3 give count/sizeof as 0 elements, array 2 gives count/sizeof as 1 element) and var_dump. Arrays 1 and 3 show 0 elements: array(0) { } whereas array 2 shows 1 element: array(1) { ["myelem2"]=> NULL } (I tested this on PHP 4.0.3pl1. is_null is not available in this version.)

« previous php.notes (#54690) next »