gpt4 book ai didi

php - $foo[bar] 和 $foo ['bar' ] 在 php 中的区别

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:05:31 25 4
gpt4 key购买 nike

我一直在很多项目中使用 $foo[bar] 而没有注意到丢失的 '

现在,我明白它为什么起作用了,我假设这是因为缺少的常量被它的名字替换了,因此指的是完全相同的数组项。

但是.. 是不是很不对还是可以接受。缺点是什么?我应该挖掘旧项目来替换它,还是性能下降真的不明显?

最佳答案

What are the downsides?

假设您有一个像 http://somesite.com/test.php?item=20 这样的 URL,

场景:1(你的情况)

<?php
echo $_GET[item]; // 20 is printed with a warning..

场景:2(最坏的情况)

<?php
define('item',20);
echo $_GET[item]; // A warning will be thrown and nothing will be printed.

Should I dig in old projects to replace this or is the performance drop on this really not noticeable?

我建议你这样做。

关于php - $foo[bar] 和 $foo ['bar' ] 在 php 中的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21576754/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com