致命错误:不再支持具有非恒定操作数的'continue'运算符 [英] Fatal error: 'continue' operator with non-constant operand is no longer supported
问题描述
我正在处理一些代码并遇到此错误,该脚本应在PHP 5.2+上运行,我正在运行5.4.27.
I'm playing with some code and getting this error, the script should work with PHP 5.2+, I'm running 5.4.27.
完全错误,Fatal error: 'continue' operator with non-constant operand is no longer supported in C:\xampp\htdocs\inc.php on line 326
第326行,continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request timeout (' . $timeout . 's)' ), true );
完整的代码部分,
public function scrape ( $announce = null, $hash_info = null, $timeout = self::timeout ) {
$packed_hash = urlencode( pack('H*', $hash_info ? $hash_info : $this->hash_info() ) );
$handles = $scrape = array();
if ( ! function_exists( 'curl_multi_init' ) )
return self::set_error( new Exception( 'Install CURL with "curl_multi_init" enabled' ) );
$curl = curl_multi_init();
foreach ( (array) ($announce ? $announce : $this->announce()) as $tier )
foreach ( (array) $tier as $tracker ) {
$tracker = str_ireplace( array( 'udp://', '/announce', ':80/' ), array( 'http://', '/scrape', '/' ), $tracker );
if ( isset( $handles[$tracker] ) )
continue;
$handles[$tracker] = curl_init( $tracker . '?info_hash=' . $packed_hash );
curl_setopt( $handles[$tracker], CURLOPT_RETURNTRANSFER, true );
curl_setopt( $handles[$tracker], CURLOPT_TIMEOUT, $timeout );
curl_multi_add_handle( $curl, $handles[$tracker] );
}
do {
while ( ( $state = curl_multi_exec( $curl, $running ) ) == CURLM_CALL_MULTI_PERFORM );
if( $state != CURLM_OK )
continue;
while ( $done = curl_multi_info_read( $curl ) ) {
$info = curl_getinfo( $done['handle'] );
$tracker = array_shift( explode( '?', $info['url'], 2 ) );
if ( empty( $info['http_code'] ) )
continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request timeout (' . $timeout . 's)' ), true );
elseif ( $info['http_code'] != 200 )
continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request failed (' . $info['http_code'] . ' code)' ), true );
$stats = self::decode_data( curl_multi_getcontent( $done['handle'] ) );
curl_multi_remove_handle( $curl, $done['handle'] );
$scrape[$tracker] = empty( $stats['files'] ) ?
self::set_error( new Exception( 'Empty scrape data' ), true ) :
array_shift( $stats['files'] ) + ( empty( $stats['flags'] ) ? array() : $stats['flags'] );
}
} while ( $running );
curl_multi_close( $curl );
return $scrape;
}
推荐答案
continue
用于跳过当前循环的其余部分,并从下一个迭代开始.您可以在后面加上一个数字,以告诉您要跳过多少循环级别直到迭代结束.如果您未指定数字,则默认为1.
continue
is used to skip the rest of the current loop, and start with the next iteration. You can put a number behind it to tell how many loop levels out are to be skipped to the end of their iteration. If you don't specify a number, the defailt is 1.
但是您要放在continue
后面的不是数字,而是语句.尝试先执行语句,然后再执行continue;
But what you are putting behind continue
not a number, but statements. Try to do the statements first, and then do continue;
所以改变:
if ( empty( $info['http_code'] ) )
continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request timeout (' . $timeout . 's)' ), true );
elseif ( $info['http_code'] != 200 )
continue $scrape[$tracker] = self::set_error( new Exception( 'Tracker request failed (' . $info['http_code'] . ' code)' ), true );
进入:
if ( empty( $info['http_code'] ) ) {
$scrape[$tracker] = self::set_error( new Exception( 'Tracker request timeout (' . $timeout . 's)' ), true );
continue;
} elseif ( $info['http_code'] != 200 ) {
$scrape[$tracker] = self::set_error( new Exception( 'Tracker request failed (' . $info['http_code'] . ' code)' ), true );
continue;
}
这篇关于致命错误:不再支持具有非恒定操作数的'continue'运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!