php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #2674 unset() does noet work inside function
Submitted: 1999-11-05 19:20 UTC Modified: 1999-11-22 21:40 UTC
From: gert at wins dot uva dot nl Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0 Beta 2 OS: Solaris 7 (x86 and SPARC) and So
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: gert at wins dot uva dot nl
New email:
PHP Version: OS:

 

 [1999-11-05 19:20 UTC] gert at wins dot uva dot nl
<?php

function bla()
{
    global      $xxxx;
    unset($xxxx);
}

$xxxx = 1;
echo "xxxx = $xxxx<br>";
unset($xxxx);
echo "xxxx = $xxxx<br>";
$xxxx = 1;
bla();
echo "xxxx = $xxxx<br>";

exit();
?>

I would expect unset() to obliterate a variable in both cases above.
For some reason unset() doesn't  do that when requested to unset
a variable declared global inside a function.

My config reads:

./configure \
        --with-mysql=/opt/mysql \
        --with-apache=../apache_1.3.9 \
        --with-config-file-path=/home/www/WWW/httpd/conf \
        --enable-track-vars \
        --enable-thread-safety \
        --with-system-regex

I don't think its relevant, but my mysql is version mysql-3.22.22.

The enable-thread-safety is not relevant (error shows with and without).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-11-22 21:40 UTC] zeev at cvs dot php dot net
This is a known incompatibility with PHP 3.0, that is consistent with the way PHP 4.0 works.

In PHP 4.0, when you write 'global $foo;' you basically hint PHP
to create a reference to the global variable $foo, with the local name $foo.

When you later on call unset($foo), PHP disallocates the local reference,
and not the global variable that reference points to.

You can unset global variables by using the special $GLOBALS array:
unset($GLOBALS["foo"]);
should work.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 06:01:34 2025 UTC