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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
1 + 40 = ?
Subscribe to this entry?

 
 [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 Mar 28 22:01:26 2024 UTC