php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33257 array_splice() inconsistent when passed function instead of variable
Submitted: 2005-06-06 17:24 UTC Modified: 2005-06-22 10:42 UTC
From: jacob at jacobweber dot com Assigned: dmitry (profile)
Status: Closed Package: Class/Object related
PHP Version: 5CVS-2005-06-19 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jacob at jacobweber dot com
New email:
PHP Version: OS:

 

 [2005-06-06 17:24 UTC] jacob at jacobweber dot com
Description:
------------
array_splice expects an array reference for its first argument. But sometimes you can pass it a function that doesn't return an array reference, and it will work.

The function has to be a static method inside a class, and it has to return a static variable of that class. In this case, array_splice will actually update the class's variable, which it shouldn't be able to do.

Even stranger, this behavior won't happen if you've assigned another variable to the result of that function.

In the example below, you only get the error message when you uncomment line 8. As far as I can tell, that should have no effect.

Reproduce code:
---------------
<?
class X {
  protected static $arr = array("a", "b", "c");
  public static function getArr() {
    return self::$arr;
  }
}
#$arr1 = X::getArr();
array_splice(X::getArr(), 1, 1);
print_r(X::getArr());
?>

Expected result:
----------------
Fatal error: Only variables can be passed by reference in test.php on line 9

Actual result:
--------------
Array
(
    [0] => a
    [1] => c
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-06-19 02:04 UTC] sniper@php.net
This is pretty magical thing. Dmitry, can you check this out?

 [2005-06-22 10:42 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC