使用数组键没有报价,如何解决它的大项目? [英] Using arrays keys without quotes, how to fix it on big project?

查看:159
本文介绍了使用数组键没有报价,如何解决它的大项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用多阵列键不带引号启动了一个项目。

I started a project using much arrays keys without quotes.

现在我有这个方法的问题,我不知道这是不好的,当我开始我的项目。我终于想显示E_NOTICES错误的原因,但它崩溃,因为日志以百万计的启事像 PHP通知超载:使用未定义的常量消息 - 假设关键

And now I having problems with this method, i didn't knew it was bad when i started my project. I finally wanted to display E_NOTICES errors for reasons but it crash because the log is overloaded with millions notices like PHP Notice: Use of undefined constant message - assumed 'key'.

因此​​,要解决这个问题,我可以在我的整个项目中添加引号,我的钥匙,但有这么多!有没有办法用algorithme或任何解决我的code来实现这一目标?我想用引号,例如,一个字符串替换任何未定义的常数:
$ my_array [关键] $ my_array ['关键']

So to fix it I could add quotes to my keys in my whole project but there are so much ! Is there a way to achieve this with an algorithme or anything to fix my code ? I want replace any undefined constant by a string with quotes, EG: $my_array[key] by $my_array['key'].

感谢。

编辑:
我成功修复使用rejex所有声明,如下所示:

I succeeded to fix all declarations using rejex, like this:

\\ [([^ 0-9 \\ $ \\'\\\\])([^ \\'\\\\] *)\\] \\ [\\'\\ 1 \\ 2 \\'\\]

但它是不够的,在有些情况下没有括号用于不带引号键多的情况下,例如:

But it is not enough, there are much situations where unquoted keys are used without brackets, EG:

array_key_exists(unquotedKey,$阵列)

$数组['关键'] =阵列(unquotedKey =>阵列(96,56));

等等......

我可以解决使用正则表达式的所有​​情况,但我想我会有多大的麻烦来处理得很好,有时候我的数组键是真正的常数,它不应该被引用!如果有人有更好的解决方案,这将有助于我很多东西。

I could fix all situations using regex but I guess I will have much troubles to handle it well, and sometimes keys of my arrays are really constants and it shouldn't be quoted ! If anybody have a better solution it would help me a lot.

完美的解决方案是能够让我的code PHP更换未定义常量后引号的字符串,这可能吗?它每次我编译的时候呢,它可能是暂时存放的地方。

The perfect solution would be to be able to get my code after PHP replaced undefined constants by quoted strings, is it possible ? It does it each time I compile, it is maybe stored somewhere temporarily.

推荐答案

我使用记事本+ + 有搜索并替换文件功能(按Ctrl + Shift + F)。与常规的前pression模式,你可以使用

I use Notepad++ which has a search and replace in files feature (Ctrl + Shift + F). With regular expression mode on, you could use

搜索:

\$my_array\[([^\'\"]+)\]

替换

\$my_array\[\'$1\'\]

搜索查找数组键方括号内的任何地方有没有一个 字符,这表明该声明已经是有效的。

The search looks for anything within the array key square brackets where there is not already a " or ' character, which would indicate the declaration is already valid.

选择您的项目的目录,然后点击文件中替换。确保整个项目备份首先在出错的时候。

Select the directory of your project then hit "Replace in Files". Ensure your entire project is backed up first in case something goes wrong.

这篇关于使用数组键没有报价,如何解决它的大项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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