dtvpl739577 2013-04-30 04:49
浏览 53

警告:非法字符串偏移'root'

I am having this error with php. The error is "Warning: Illegal string offset 'root' " this is the actual code on the line

$root = $atts['root'];

any help would be appreciated

  • 写回答

1条回答 默认 最新

  • dongwei4444 2013-04-30 05:10
    关注

    In PHP, the $var[$index] syntax works with both arrays and with strings. With an array, this will return the element at index $index in array $var ($index can either be a string, meaning $var is an associative array, or an integer, meaning it is a normal array (I'm sure there's a better term for it but I'm not familiar).

    With a string, $index (called an offset in this case) can only be an integer, and will return the character at position $index in the string. So if you have $var = 'this is my string';, then $var[2] would return the letter 'i' from "this" (remember that indeces start at 0 for both arrays and strings).

    So in this case, it is clear that you are expecting $atts to be an array, but it is in fact a string. Because of this you cannot retrieve an index from another string ('root'), rather only an integer. For this reason, you are getting the error, which pretty much sums up what I wrote above. Using a string as an index, or an offset, for another string, is illegal (you can only use integers).

    Without seeing more of your code I won't be able to tell why $atts is a string and not an array as you expect, but this will hopefully help you understand why you are getting that error.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?