|  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
 [2005-06-06 17:24 UTC] jacob at jacobweber dot com
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);

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

Actual result:
    [0] => a
    [1] => c


Add a Patch

Pull Requests

Add a Pull Request


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

 [2005-06-22 10:42 UTC]
Fixed in CVS HEAD and PHP_5_0.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jul 13 19:01:30 2024 UTC