php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #7890 Recursion problem with isset and unset
Submitted: 2000-11-20 06:58 UTC Modified: 2000-11-20 08:00 UTC
From: nickj at ihug dot com dot au Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.3pl1 OS: Linux Mandrake 7.2
Private report: No CVE-ID: None
 [2000-11-20 06:58 UTC] nickj at ihug dot com dot au
I have a problem with a recursive function call that does not work as I would expect. A short script that reproduces the problem is:

<?php
    function fn() {
        global $test;
        if (isset($test)) {
            print "test is set<br>\n";
            unset($test);
            fn();
        }
        else {
            print "test is NOT set<br>\n";
        }   
    }   
        

    $test = array("exam_id" => "MATH_101", "exam_code" => "Mathematics Intro");
    fn();
?>

What Happens: - out produced is:
test is set
test is set
test is set
test is set
test is set
test is set
... [and so on] ...

What I would expect to happen - looking for this output:
test is set 
test is NOT set
[end of output]


Setup Information:
Configure command from phpinfo() gives: "'./configure' '--with-apxs=/usr/sbin/apxs' '--without-mysql' '--disable-static' '--disable-debug' '--enable-pic' '--enable-inline-optimization' '--prefix=/usr' '--with-zlib' '--with-config-file-path=/etc' '--enable-magic-quotes' '--enable-debugger' '--enable-track-vars' '--enable-safe-mode' '--with-exec-dir=/usr/bin' '--with-regex=system' '--with-versioning' '--enable-dba=shared' '--with-gdbm' '--with-db2' '--enable-sysvsem' '--enable-sysvshm' '--with-mod_charset' '--enable-force-cgi-redirect' '--with-mm' '--enable-trans-sid' '--with-dbase' '--with-filepro' '--enable-yp' '--enable-ftp' '--with-xml' '--with-gettext'"

Also using Zend engine (don't know if this is relevant) : "This program makes use of the Zend scripting language engine: Zend Engine v1.0.3, Copyright (c) 1998-2000 Zend Technologies with Zend Optimizer v0.99, Copyright (c) 1998-2000, by Zend Technologies"

Any other information I can supply that would assist, just email me and let me know. Of course, it could just be something obviously and embarrassingly wrong in the code above, but if it is, I honestly can't see it.

Cheers,
Nick.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-11-20 08:00 UTC] hholzgra@php.net
'global $test' creates a reference to $GLOBALS['test']
and 'unset($test)' will only unset this reference

you have to write 'unset($GLOBALS['test']) to unset
the variable in the global scope
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sat Oct 10 08:00:02 2026 UTC