【问题标题】:phplint undeclared functionphplint 未声明的函数
【发布时间】:2014-02-27 12:04:48
【问题描述】:

我正在使用 phplint 来检查我的 PHP 代码。我是 Windows 8.1,我的编辑器是 Sublime Text 3。 这是我的一个小代码sn-p:

<?php
header("Content-type: image/png");

$singleHeight = 129;
$singleWidth = 97;
$bild = imagecreatetruecolor(1170, 520);
$orange = imagecolorallocate($bild, 248, 154, 38);
imagefill($bild, 0, 0, $orange);

....

?>

这是 phplint 报告:

1: 函数“header()”(仍然)未声明。从它的使用中猜测签名。提示:最好在使用前声明函数
1:未声明的函数 'header()' 只使用了一次:拼写错误?
3:变量“$singleHeight”已分配但从未使用过
4:变量“$singleWidth”已分配但从未使用过
5:函数“imagecreatetruecolor()”(仍然)未声明。从它的使用中猜测签名。提示:最好在使用前声明函数
5:未声明的函数“imagecreatetruecolor()”只使用了一次:拼写错误?
6: 函数 'imagecolorallocate()' (仍然)未声明。从它的使用中猜测签名。提示:最好在使用前声明函数
6:未声明的函数“imagecolorallocate()”只使用了一次:拼写错误? 7: 函数'imagefill()'(仍然)未声明。从它的使用中猜测签名。提示:最好在使用前声明函数
7:未声明的函数“imagefill()”只使用了一次:拼写错误?

未声明的函数是什么?代码本身运行良好。

【问题讨论】:

    标签: php sublime-text-plugin phplint


    【解决方案1】:

    我假设你正在使用这个 PHPLint http://www.icosaedro.it/phplint/phplint-on-line.html ?

    默认情况下,它似乎不加载任何标准库,因此当您检查代码时,linter 是从头开始的,没有声明任何内容。

    当您在服务器上运行代码时,像 GD 和标准 PHP 函数(如标头)已启用,因此它可以正常工作。

    您可以通过将这些库添加到代码顶部来解决此问题

    <?php /*. require_module 'gd'; .*/ ?>
    <?php /*. require_module 'standard'; .*/ ?>
    <?php
    header("Content-type: image/png");
    
    $singleHeight = 129;
    $singleWidth = 97;
    $bild = imagecreatetruecolor(1170, 520);
    $orange = imagecolorallocate($bild, 248, 154, 38);
    imagefill($bild, 0, 0, $orange);
    

    这将像这样输出

    BEGIN parsing of test-32AOqf
    1:      <?php /*. require_module 'gd'; .*/ ?>
    2:      <?php /*. require_module 'standard'; .*/ ?>
    3:      <?php
    4:      header("Content-type: image/png");
    5:      
    6:      $singleHeight = 129;
    7:      $singleWidth = 97;
    8:      $bild = imagecreatetruecolor(1170, 520);
    9:      $orange = imagecolorallocate($bild, 248, 154, 38);
    10:     imagefill($bild, 0, 0, $orange);
    END parsing of test-32AOqf
    ==== test-32AOqf:7: notice: variable `$singleWidth' assigned but never used
    ==== test-32AOqf:6: notice: variable `$singleHeight' assigned but never used
    ==== ?: notice: unused package `stdlib/dummy.php'
    ==== ?: notice: unused module `mysql'
    ==== ?: notice: unused module `pcre'
    ==== ?: notice: required module `standard'
    ==== ?: notice: required module `gd'
    Overall test results: 0 errors, 0 warnings.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-31
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多