php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48903 Lambda function as array index
Submitted: 2009-07-13 13:29 UTC Modified: 2009-07-13 13:50 UTC
From: ninzya at inbox dot lv Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0 OS: Windows XP
Private report: No CVE-ID: None
 [2009-07-13 13:29 UTC] ninzya at inbox dot lv
Description:
------------
See reproduce code.

Reproduce code:
---------------
<?php

$arr =array();

$arr[function(){return 5;}] ='Stepanov';

var_dump( $arr);

?>

Expected result:
----------------
array(1) {
  [5]=>
  string(8) "Stepanov"
}

Actual result:
--------------
Warning: Illegal offset type in D:\...\index.php on line 5
array(0) {
}

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-13 13:34 UTC] colder@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

You can't, as usual, use objects as array keys.

Check out SplObjectStorage.
 [2009-07-13 13:50 UTC] ninzya at inbox dot lv
Yep, my typo, just figured out. Incorrectly used lambdas.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 25 00:00:02 2025 UTC