php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51794 String keys in arrays are treated as 0, if not set
Submitted: 2010-05-11 16:07 UTC Modified: 2010-05-11 22:03 UTC
From: schmunk at usrbin dot de Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.3.2 OS: OS X 10.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: schmunk at usrbin dot de
New email:
PHP Version: OS:

 

 [2010-05-11 16:07 UTC] schmunk at usrbin dot de
Description:
------------
I tried to access an array key by string value.
But the variable I accessed was no array, but a string.

As stated in the manual you can access single chars by numeric array keys, which 
makes perfect sense.
But if I try to use a string it is treated as 0 (zero).

Too much type jugglin'?

Test script:
---------------
<?php 
  $link = "foo";
  echo $link['bar'];
?>

Expected result:
----------------
PHP NOTICE - $link['bar'] is not defined.

Actual result:
--------------
f

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-11 22:03 UTC] dtajchreber@php.net
-Status: Open +Status: Bogus
 [2010-05-11 22:03 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

"Warning

Writing to an out of range offset pads the string with spaces. Non-integer types are converted to integer. Illegal offset type emits E_NOTICE. Negative offset emits E_NOTICE in write but reads empty string. Only the first character of an assigned string is used. Assigning empty string assigns NUL byte."

See: http://www.php.net/manual/en/language.types.string.php
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 00:01:41 2024 UTC