PHP 中是否发生了一些变化,将变量声明为字符串,然后将其用作数组是不行的。我们升级到了 bitnamies wamp stack,它破坏了我们的应用程序。变量之一
$change="";
后来用了
$change[$k] = "this";
它仍然是单个字符串,而不是变成数组。这是我可以更改的 php.ini 配置吗?
最佳答案
从 7.1 开始,您描述的行为发生了变化。请参阅 Assignment via string index access on an empty string 的更改日志
String modification by character on an empty string now works like for non-empty strings, i.e. writing to an out of range offset pads the string with spaces, where non-integer types are converted to integer, and only the first character of the assigned string is used. Formerly, empty strings where silently treated like an empty array.
<?php
$change='';
$change[2] = "this";
var_dump($change);
/*
Prior to 7.1:
array(1) {
[2]=>
string(4) "this"
}
7.1 and up:
string(3) " t"
PHP 7 已经有了许多改进,使“更严格”的输入成为可能,并允许更好的 type hinting 。尽管如此,PHP 仍然被认为是一种松散类型的语言。一些示例包括,从 7.0 开始,Scalar type declarations , Return type declarations和 strict_types
指令。
关于php - 将变量声明为字符串,然后将其用作数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64146031/