php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2692 clarification: unset and reference
Submitted: 1999-11-10 13:05 UTC Modified: 2000-03-10 12:41 UTC
From: php-bug at vogtner dot de Assigned:
Status: Closed Package: Misbehaving function
PHP Version: 4.0 Beta 2 OS: any
Private report: No CVE-ID: None
 [1999-11-10 13:05 UTC] php-bug at vogtner dot de
<%    
   function sub (&$v)
   {  
      unset ($v);
      $v = 66;
   }  
      
   sub ($s);
   echo '<br>$s = '. $s . "\n"; 
   echo '<br>isset ($s) = '. isset ($s) . "\n"; 
%> 

(a) unset breaks the reference between local $v
and parameter $s.

(b) $s becomes defined (no more warnings) by taking
a reference but it is not set.

Will this be documented?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-14 03:02 UTC] joey at cvs dot php dot net
${$v} should work for a dereference operator, right?
If you compare the output of the script below with that
of the original example above, you will see that "dereferencing"
unset($v) is no longer breaking the reference...

Moving to "Misbehaving function". unset() should not break
ref.


<?
  function sub (&$v)
 {  
unset (${$v});
 $v = 66;
 }  
                                      
 sub ($s);
 echo '<br>$s = '. $s . "\n"; 
 echo '<br>isset ($s) = '. isset ($s) . "\n";
?>
 [2000-03-10 12:41 UTC] andi at cvs dot php dot net
unset() within a function removes the variable from the functions symbol table. It doesn't actually nuke the outside variable. You could assign NULL to the variable.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 07:01:30 2024 UTC