Альтернатива NCover может быть PartCover, инструмент покрытия открытого исходного кода для.NET, очень похожей на NCover, это включает консольное приложение, браузер покрытия GUI, и XSL преобразовывает для использования в CruiseControl.NET .
Это - очень интересный продукт.
OpenCover заменил PartCover.
PHP has a direct equivalent called generators.
Old (pre php 5.5 answer):
Unfortunately, there isn't a language equivalent. The easiest way is to either to what you're already doing, or to create a object that uses instance variables to maintain state.
There is however a good option if you want to use the function in conjunction with the foreach-statement: SPL Iterators. They can be used to achieve something quite similar to python generators.
Я прототипирую все на Python, прежде чем реализовывать на любых других языках, включая PHP. В итоге я использовал обратные вызовы, чтобы добиться того, что я хотел бы с yield
.
function doSomething($callback)
{
foreach ($something as $someOtherThing) {
// do some computations that generates $data
call_user_func($callback, $data);
}
}
function myCallback($input)
{
// save $input to DB
// log
// send through a webservice
// etc.
var_dump($input);
}
doSomething('myCallback');
Таким образом, каждый $ data
передается функции обратного вызова, и вы можете делать то, что хотите.
Эквивалентного оператора может не быть, но следующий код эквивалентен по функциям и накладным расходам:
function file_lines($file) {
static $fhandle;
if ( is_null($fhandle) ) {
$fhandle = fopen($file, 'r');
if ( $fhandle === false ) {
return false;
}
}
if ( ($line = fgets($fhandle))!== false ) {
return $line;
}
fclose($fhandle);
$fhandle = null;
}
while ( $line = file_lines('some_file') ) {
// ...
}
Это выглядит примерно правильно. Извините, я не тестировал.