使用 Simpletest PHP“PHP 单元测试”,收到错误消息“已弃用:不推荐通过引用分配 new 的返回值”

发布于 2024-09-08 02:42:17 字数 1169 浏览 3 评论 0原文

我刚开始使用 simpletest: http://www.simpletest.org/ for PHP 并且正在使用 PHP 5.2* 在我的服务器上,当我尝试根据他们的演示设置初始测试脚本时,我得到一个充满错误的页面,如下所示...我不确定这是否与 simpletest 不兼容有关对于 PHP 5.* 或问题是什么,任何见解都值得赞赏..似乎我仍然可以使用该库,因为它返回错误下方似乎合适的内容,但我想了解这一点,以便我可以修复它..谢谢

这是我用来调用 simpletest 函数的 php 代码的示例

<?php

require_once('C:/wamp/www/external/simpletest/simpletest/autorun.php');


class TestOfLogging extends UnitTestCase {
    function testFirstLogMessagesCreatesFileIfNonexistent() {
        @unlink(dirname(__FILE__) . '/../temp/test.log');
        $log = new Log(dirname(__FILE__) . '/../temp/test.log');
        $log->message('Should write this to a file');
        $this->assertTrue(file_exists(dirname(__FILE__) . '/../temp/test.log'));
    }
}
?>

以及我得到的错误:

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\external\simpletest\simpletest\unit_tester.php  on line 74

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\external\simpletest\simpletest\unit_tester.php on line 89

I am new to using simpletest: http://www.simpletest.org/ for PHP and am using PHP 5.2* on my server, when I try to set up an initial test script based on their demo, I get a page full of errors like the one below... I am not sure if this is something to do with simpletest not being compatible with PHP 5.* or what the issue is, any insight is appreciated.. it seems that I can still use the library as it returns what seems to be appropriate below the errors, but I would like to understand this so I can fix it.. thanks

Here is an example of the php code I am using to call a simpletest function

<?php

require_once('C:/wamp/www/external/simpletest/simpletest/autorun.php');


class TestOfLogging extends UnitTestCase {
    function testFirstLogMessagesCreatesFileIfNonexistent() {
        @unlink(dirname(__FILE__) . '/../temp/test.log');
        $log = new Log(dirname(__FILE__) . '/../temp/test.log');
        $log->message('Should write this to a file');
        $this->assertTrue(file_exists(dirname(__FILE__) . '/../temp/test.log'));
    }
}
?>

And the error I get:

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\external\simpletest\simpletest\unit_tester.php  on line 74

Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\external\simpletest\simpletest\unit_tester.php on line 89

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

黑寡妇 2024-09-15 02:42:17

“已弃用”意味着一些老式的东西,可能不会被未来版本的 php 支持。它不应该是有害的,但应该由 simpletest 开发人员处理。您下载了最新版本的 simpletest 吗?
如果你想了解的话,请看一下unit_tester.php的第74行和第89行。

"Deprecated" means that something old-fashion, that possibly won't be supported by future versions of php is done. It should not be harmful, but should be taken care of by simpletest developers. Did you download the latest version of simpletest?
If you want to understand, take a look at unit_tester.php on lines 74 and 89.

爱殇璃 2024-09-15 02:42:17

不必关闭所有错误,只需关闭弃用警告。另一种方法是对所有简单的测试文件进行查找和替换:查找“&new”并替换为“new”。 new 通过引用 (&new) 仅为 在 PHP5.3 中已弃用,因此希望在下一个 SimpleTest 版本中能够修复该问题。

Rather than switching all errors off, just switch off deprecation warnings. The alternative is to do a find-and-replace on all the simpletest files: find "&new" and replace with "new". new by reference (&new) was only deprecated in PHP5.3, so hopefully that'll be fixed in the next SimpleTest release.

有木有妳兜一样 2024-09-15 02:42:17

您确定在运行单元测试时使用的是 5.2,而不是 5.3?我似乎记得在 5.3 下运行 PEAR 包时看到这些错误。

Are you sure you're using 5.2, and not 5.3, when running the unit tests? I seem to remember seeing these errors with PEAR packages running under 5.3.

残花月 2024-09-15 02:42:17

我在学习 simpletest 教程时也遇到了这个问题。

为了让这些消息消失,我将 php.ini 文件中的 display_errors = On 设置更改为 display_errors = Off

I also had this problem while going through the simpletest tutorial.

To make these messages go away, I changed the display_errors = On setting in my php.ini file to display_errors = Off.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文