琴弦为什么表现得像在PHP 5.3数组? [英] Why do strings behave like an array in PHP 5.3?

查看:235
本文介绍了琴弦为什么表现得像在PHP 5.3数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的code:

$tierHosts['host'] = isset($host['name']) ? $host['name'] : $host;

它的正常工作在PHP 5.5,但在PHP 5.3的条件下返回true,而 $主机包含像 pjba01 。它返回的第一个字母 $ tierHosts ['主机'] ,即 P

It's working fine in PHP 5.5, but in PHP 5.3 the condition returns true while $host contains a string like pjba01. It returns the first letter of $tierHosts['host'], that is, p.

这有什么错我的code?

What's so wrong with my code?

推荐答案

您可以访问字符串像数组和以前的PHP 5.4偏移喜欢你的名称被静静地铸造为0,意味着你访问该字符串的第一个字符:

You can access strings like an array and prior PHP 5.4 offsets like your name were silently casted to 0, means you accessed the first character of that string:

character | p | j | b | a | 0 | 1 |
-----------------------------------
index     | 0 | 1 | 2 | 3 | 4 | 5 |

在5.3这样的偏移将抛出一个通知,你还可以在手册中读到:

After 5.3 such offsets will throw a notice, as you can also read in the manual:

随着PHP 5.4字符串偏移量必须要么是整数或整数样的字符串,否则警告将被抛出。 previously一个像富偏移悄悄转换为0。

As of PHP 5.4 string offsets have to either be integers or integer-like strings, otherwise a warning will be thrown. Previously an offset like "foo" was silently cast to 0.

这篇关于琴弦为什么表现得像在PHP 5.3数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆