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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 20:01:36 2025 UTC