php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70853 SplFixedArray throws exception when using ref variable as index
Submitted: 2015-11-04 13:01 UTC Modified: -
From: php at maisqi dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 7.0.0RC6 OS: Windows 8 x64
Private report: No CVE-ID: None
 [2015-11-04 13:01 UTC] php at maisqi dot com
Description:
------------
PHP7 throws an exception if we try accessing a member by an index stored in a referenced variable.
In other words, if we have the index in $var and, by one reason or another, make a reference to it (like $ndx2 =& $ndx) we no longer can use it to access a SplFixedArray. (We would have to copy $ndx, or $ndx2, to a temp normal variable and use it instead.)

Test script:
---------------
<?php

$list = new SplFixedArray(10);
$ndx = 1;
$ndx2 =& $ndx;
$list[$ndx] = 123;	// This throws an exception;
$list[$ndx2] = 123;	// as does this, to.
echo 'ok';


Expected result:
----------------
It should just print "ok".

Actual result:
--------------
"Uncaught RuntimeException: Index invalid or out of range"

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-04 14:45 UTC] laruence@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e4ac4e75b5dbc39ed52ff998cb4f2053541ed2d8
Log: Fixed bug #70853 (SplFixedArray throws exception when using ref variable as index)
 [2015-11-04 14:45 UTC] laruence@php.net
-Status: Open +Status: Closed
 [2015-11-09 18:12 UTC] ab@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b48738f00b115eda59163016c24a417bef1eeda9
Log: Fixed bug #70853 (SplFixedArray throws exception when using ref variable as index)
 [2016-07-20 11:35 UTC] davey@php.net
Automatic comment on behalf of laruence@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e4ac4e75b5dbc39ed52ff998cb4f2053541ed2d8
Log: Fixed bug #70853 (SplFixedArray throws exception when using ref variable as index)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 10:01:29 2024 UTC