gpt4 book ai didi

phpUnit 因奇怪的错误而失败

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

PHP Fatal error:  Default value for parameters with a class type hint can only be NULL in /usr/share/php/PHPUnit/Framework/Test.php on line 66
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpunit:0
PHP 2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP 3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:130
PHP 4. PHPUnit_Runner_BaseTestRunner->getTest() /usr/share/php/PHPUnit/TextUI/Command.php:150
PHP 5. PHPUnit_Runner_BaseTestRunner->loadSuiteClass() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:104
PHP 6. PHPUnit_Runner_StandardTestSuiteLoader->load() /usr/share/php/PHPUnit/Runner/BaseTestRunner.php:168
PHP 7. PHPUnit_Util_Fileloader::checkAndLoad() /usr/share/php/PHPUnit/Runner/StandardTestSuiteLoader.php:78
PHP 8. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:79
PHP 9. include_once() /usr/share/php/PHPUnit/Util/Fileloader.php:95
PHP 10. phpunit_autoload() /usr/share/php/PHPUnit/Autoload.php:0
PHP 11. require() /usr/share/php/PHPUnit/Autoload.php:203
PHP 12. phpunit_autoload() /usr/share/php/PHPUnit/Autoload.php:0

有问题的行有:

公共(public)函数运行(PHPUnit_Framework_TestResult $result = NULL)

当我删除 = NULL 时,它通过了但在另一行也有 = NULL 时失败了,搞砸的是错误基本上说它有为 NULL,它是。

我没有以任何方式修改 PhpUnit,我使用此处描述的方法安装它:

http://www.giocc.com/installing-phpunit-on-ubuntu-11-04-natty-narwhal.html

老实说,我不明白为什么会这样。有些东西告诉我 PHP 有问题,因为它给了我错误的错误。

最佳答案

找到答案了,引用自评论区:

Oh damn I found the problem, and it's a silly one on my side. I had a constant file that was defining NULL for use in an ORM library. It's defined in it's own namespace so it shouldn't have interfered with the global constant, but I guess constants are a bit tricky with namespaces..

所以直到,如果你想在命名空间中定义常量,仅仅在文件顶部添加命名空间是不够的,你必须像这样定义常量

define('NAMESPACE\CONSTANT',        'value');
// or
define(__NAMESPACE__ . '\CONSTANT', 'value'); // to use the current namespace

关于phpUnit 因奇怪的错误而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9166463/

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