php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52114 Array key moves when using func_get_args()
Submitted: 2010-06-17 22:34 UTC Modified: 2010-06-18 01:56 UTC
From: iblue at gmx dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: Ubuntu Linux 10.04
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: iblue at gmx dot net
New email:
PHP Version: OS:

 

 [2010-06-17 22:34 UTC] iblue at gmx dot net
Description:
------------
Arrays get scrambled when using func_get_args(). See code sample below.

Test script:
---------------
<?php
function foo(/* ... */) {
  $arguments = func_get_args();
  if(isset($arguments[0]['key'])) {
    var_dump($arguments[0]);
    var_dump($arguments[1]);
    echo "You see that \$arguments[0] is a string, while \$arguments[1] is an array.\n";
    echo "So this code should never get executed.\n";
  } else {
    echo "Correct behaviour";
  }
}

foo("some string", array("key" => "value"));

Expected result:
----------------
Script output:
Correct behaviour

Actual result:
--------------
Script output:
string(11) "some string"
array(1) {
  ["key"]=>
  string(5) "value"
}
string(1) "s"
You see that $arguments[0] is a string, while $arguments[1] is an array.
So this code should never get execute.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-18 01:56 UTC] dtajchreber@php.net
-Status: Open +Status: Bogus
 [2010-06-18 01:56 UTC] dtajchreber@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

$arguments[0] is a string. $arguments[0]['key'] refers to an offset in said 
string. Non-integer offsets are converted to integers. Since the string 'key' 
doesn't contain any valid numeric data, it turns into a 0.. so you're checking if 
the first character of the string is set... it is. :)

Read through this page for a more detailed explanation: 
http://www.php.net/manual/en/language.types.string.php
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 12:01:33 2025 UTC