php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68162 isset($$varname) always true
Submitted: 2014-10-06 04:51 UTC Modified: -
From: pegasus at vaultwiki dot org Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: master-Git-2014-10-06 (Git) OS: Centos 6 64-bit
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pegasus at vaultwiki dot org
New email:
PHP Version: OS:

 

 [2014-10-06 04:51 UTC] pegasus at vaultwiki dot org
Description:
------------
It seems that isset (likely others like unset, empty, etc) cannot properly resolve variably-named variables and simply returns true.

Test script:
---------------
function testWrapper()
{
	foreach (array(
		'testvar1',
		'testvar2'
	) AS $varname)
	{
		if (!isset($$varname))
		{
			echo "\nSetting $varname\n";
			$$varname = array();
		}

		var_dump($$varname);
	}
}

testWrapper();

Expected result:
----------------
Setting testvar1
array(0) {}
Setting testvar2
array(0) {}

Actual result:
--------------
NULL
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-06 17:03 UTC] nikic@php.net
I can't repro this.
 [2014-10-06 18:01 UTC] pegasus at vaultwiki dot org
Strange. I thought I was going crazy for a bit, then I tried messing around with actually trying to use the arrays created by the test. The testWrapper above indeed works normally on its own, but add the following immediately after the foreach loop in testWrapper:

####
$testvar1 = array_merge($testvar1, array());
$testvar2[] = true;
####
 [2014-10-06 18:39 UTC] nikic@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e24c24c1087c6405e842fdd7afcd84b224eb75bf
Log: Fix bug #68162: isset($$varname) always true
 [2014-10-06 18:39 UTC] nikic@php.net
-Status: Open +Status: Closed
 [2014-10-07 07:10 UTC] ab@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e24c24c1087c6405e842fdd7afcd84b224eb75bf
Log: Fix bug #68162: isset($$varname) always true
 [2016-07-20 11:40 UTC] davey@php.net
Automatic comment on behalf of nikic
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e24c24c1087c6405e842fdd7afcd84b224eb75bf
Log: Fix bug #68162: isset($$varname) always true
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC