目前,我正坐在PHP5.6上,很快就会更新到PHP8。我使用PHPCS检查了兼容性问题,并在升级到PHP8之前修复了这些问题。
但是,我在测试过程中发现了一些与代码中的类型调整相关的问题,例如:
$x = "";
$x['test'] = "xyz";
print_r($x); //Warning: Only the first byte will be assigned to the string offset in /tmp/8dw2cmkrbq0pcq/tester.php on line 4 Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /tmp/8dw2cmkrbq0pcq/tester.php:4 Stack trace: #0 {main} thrown in /tmp/8dw2cmkrbq0pcq/tester.php on line 4这段代码在PHP5.6中运行良好。
不幸的是,PHPCS没有检测到这个问题,现在我想知道产品中是否有更多类似的问题。
现在,我想知道是否有方法可以在我升级到PHP8之前检测到这些问题?如果我能在升级到PHP8之前得到一些关于如何找到这样的问题的提示,那将是非常有帮助的。
发布于 2021-07-23 13:28:55
我能够使用https://github.com/phan/phan检测到这种类型的问题。下面是捕获到的示例问题。
{
"type": "issue",
"type_id": 10030,
"check_name": "PhanTypeMismatchDimAssignment",
"description": "TypeError PhanTypeMismatchDimAssignment When appending to a value of type '', found an array access index of type 'hobbies', but expected the index to be of type int",
"severity": 5,
"location": {
"path": "PQR/models/XYZModel.php",
"lines": {
"begin": 171,
"end": 171
}
}}感谢你们的支持。
https://stackoverflow.com/questions/68451014
复制相似问题