php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48142 Confusing behavior
Submitted: 2009-05-04 09:46 UTC Modified: 2009-05-04 11:32 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: smh at wannafind dot dk Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.9 OS: Linux 2.6.24.3-50.fc8
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: smh at wannafind dot dk
New email:
PHP Version: OS:

 

 [2009-05-04 09:46 UTC] smh at wannafind dot dk
Description:
------------
Requesting a string index on a string type using the string as an array always returns first character position in string.

Reproduce code:
---------------
<?php
$input = '386';
echo $input . " / " . $input['tessrthwsrtht'] . "\n";
?>

Expected result:
----------------
PHP should generate an error when this occurs, because this situation occurs when you think a method/function returns a string indexed array but really just returns a string.
In this situation you get some data, but the data is incorrect and this can be very confusing to debug.

Actual result:
--------------
PHP casts the string index to an integer with the value: 0 and returns the first character in the string.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-04 11:32 UTC] scottmac@php.net
Adding new errors would result in breaking backwards compatibility so it isn't really practical to change.

You could add an array typehint to parameters to add extra checking.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 07:01:31 2024 UTC