Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Consistency. Since $a[0] is a string, you would expect $a[0][0] to work too.


Thanks. Let me rework my original question then. Why the hell didn't it always work?

  php > $a = "Hello";
  php > echo $a[0];
  H
  php > echo $a[0][0];
  PHP Fatal error:  Cannot use string offset as an array in php shell code on line 1


PHP always seemed to have something weird in the parser about subscripts/array indexes. It's been there since I started using it during PHP3. Another similar fix they performed is making func()[0] work - before you had to do $tmp = func(); $tmp[0]. An old, old bug finally fixed.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: