English 中文(简体)
PHP 4 到 PHP 5 - 如果对帐单
原标题:PHP 4 to PHP 5 - isset checks on boolean if statements

Scenario: We are in the process of converting an application from PHP 4 to PHP 5. The application needs to be able to work on PHP 4 f或a little while, which means no PHP 5 specific elements can be used, yet. We are simply trying to make sure the application works on both platforms.

应用程序中有许多条件都像这样:

if ($variable) { // do something }

其中一些变数最终完全没有定义,我们正在试图减少误差数量(其中很多是误差)。

为了解决这些错误, 我们正在多个领域添加检查 :

if (!isset($variable)) $variable = "";

if (!empty($variable)) { // do something }

Question: Does anyone know of a simpler approach to fixing these errors. The problem is that these variables are being used across files (via includes) and defining the variable may change the logical flow in that file if its doing a check like (if (!isset($variable)) { // do something }).

The point of this question is to reduce errors and time consumption of tracking each individual use of these variables. Currently, we are having to either examine thoroughly what the variable is doing (which may take a good chunk of time), 或we are doing a "fire and forget" / hope-its-fixed method of correcting.

-- Edit -- Does anyone know of a program like cppcheck f或php that could somehow reference these variables 或create some kind of chaining that could find errors and link possible references? (I hope that makes sense.)

最佳回答

AFAIK 有一个代码检查器, 寻找未初始化的变量, 有效 。 您可以通过它进行 s mess 。 您可以通过它的消息工作 。 它叫做 < a href=" http://phpmd. org/" rel=" nofollow noreferrer" > PHPP Mess 探测器 , 其中一条规则包含未初始化变量 。 但是这永远无法完美 。

另一种方法是跟踪错误信息, 并使用它来定位代码中的位置 。 过去我曾经这样做过, 并且效果很好, 只要在迭代中做, 并记录警告 。

您也可以使用白色列表, 并在请求启动时导入白色列表变量。 非白色列表的提交需要导致访问违反错误, 才能正常运行, 这样比跟踪警告更管用, 尽管它可能会使您的应用程序更加安全 。

另见:

问题回答

暂无回答




相关问题
Copy data from Access to SQL

I am in the process of migrating an existing Access database to a SQL database with a web front-end. I have successfully copied the database to SQL using the SQL Server Migration tool and am working ...

MongoMapper and migrations

I m building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document ...

Switching to WPF. Is it time?

I m considering switching from MFC to WPF. My first concern is that there are too many users who don t have .NET with WPF installed yet. Can anybody point to a source containing the WPF penetration ...

rake db:migrate running all migrations correctly

I m fairly new to Ruby on Rails here. I have 2 migrate files that were provided. The first one, prefixed with 001, creates a table and some columns for that table. The next migrate file, prefixed ...

Migrate Java Applet to what/where?

I am reviewing currently a medium size code base (around 30K LOC) which uses a huge Applet and interfaces with other systems. It s a tool to create custom labels, so we need drag-n-drop and other ...

热门标签