【发布时间】:2016-07-30 15:51:37
【问题描述】:
只是试图保存和修复来自PHPBench.com的源
并遇到此错误(网站已关闭且作者未回答问题)。这是来源:
<?php
// Initial Configuration
class SomeClass {
function f() {
}
}
$i = 0; //fix for Notice: Undefined variable i error
// Test Source
function Test6_2() {
//global $aHash; //we don't need that in this test
global $i; //fix for Notice: Undefined variable i error
/* The Test */
$t = microtime(true);
while($i < 1000) {
$obj =& new SomeClass();
++$i;
}
usleep(100); //sleep or you'll return 0 microseconds at every run!!!
return (microtime(true) - $t);
}
?>
它是否是有效的语法?如果我错了,请纠正我,但认为它创建了对 SomeClass 的引用,因此我们可以致电 new $obj() ...提前感谢您的帮助
【问题讨论】:
-
=& new ...是无效语法 -
类实例需要赋值给一个变量,所以你必须把实例赋值给一个变量,然后把变量的引用放到
$obj,但是我的问题是,你为什么需要参考吗? -
这是测试-创建新对象时
= new和=& new之间的比较 -
语法自
PHP 5.0被弃用并在PHP 7.0中被删除。PHP 5.0说Strict Standards: Assigning the return value of new by reference is deprecated3v4l.org/AKH8r -
正如我所说,这是来自已经非活动站点的代码:)