php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32522 String offsets REALLY weird
Submitted: 2005-03-31 21:49 UTC Modified: 2005-03-31 22:05 UTC
From: php at alterego dot dp dot ua Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.0.3 OS: FreeBSD 4.10
Private report: No CVE-ID: None
 [2005-03-31 21:49 UTC] php at alterego dot dp dot ua
Description:
------------
Strings offsets in PHP5 are broken strangely. Seems like repeated offsets are not allowed at all, even at the times where they make good sense.

I see nothing fatal in $a[0][0] or even $a{0}{0} or even $a[0]{0}[0] if $a is a non-empty string. And PHP5 just crashes at any one of them.

Why $a{0} can't be a string without extra intermediate assignment?

Please, look at the code before marking bogus.

Reproduce code:
---------------
<?
$a = '0';
$b = $a[0];
echo $b[0];

$a = '0';
// leave any one line of the next few
echo $a[0][0];
echo $a[0]{0};
echo $a{0}{0};
echo $a[0]{0}[0];
?>

Expected result:
----------------
00

Actual result:
--------------
0
Fatal error: Cannot use string offset as an array in /www/test.php on line 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-03-31 21:56 UTC] sniper@php.net
If it worked in PHP4, it doesn't mean it will work in PHP 5 where it's behaving like it should have behaved in PHP 4 too..

And $a[0][0] is not same as when you assign it first..

 [2005-03-31 22:05 UTC] php at alterego dot dp dot ua
I do not expect PHP5 to be PHP4. I just expect it to be consistent in some way.

Would you please be so kind as to give me a gentle hint of what is wrong with $a{0}{0} (CURLY BRACES).

Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 03:01:28 2024 UTC