I’m using the PHP-FineDiff class as a service in my project. Creating diff works fine, however, when I try to restore the diffs using e.g. FineDiff::renderToTextFromOpcodes(), nothing happens.
I digged a little in the code and found that a callback doesn’t work. After commenting out some
if ( !is_callable($callback) ) {
return;
}
I run into the error:
Warning: call_user_func() expects parameter 1 to be a valid callback, class ‘FineDiff’ not found in /var/www/sopos-blog/src/Sopos/WikiBundle/Services/FineDiff.php line 321.
These are some relevant lines of code:
public static function renderToTextFromOpcodes($from, $opcodes) {
ob_start();
FineDiff::renderFromOpcodes($from, $opcodes, array('FineDiff','renderToTextFromOpcode'));
return ob_get_clean();
}
// ...
public static function renderFromOpcodes($from, $opcodes, $callback) {
if ( !is_callable($callback) ) {
return;
}
$opcodes_len = strlen($opcodes);
$from_offset = $opcodes_offset = 0;
while ( $opcodes_offset < $opcodes_len ) {
$opcode = substr($opcodes, $opcodes_offset, 1);
$opcodes_offset++;
$n = intval(substr($opcodes, $opcodes_offset));
if ( $n ) {
$opcodes_offset += strlen(strval($n));
}
else {
$n = 1;
}
if ( $opcode === 'c' ) { // copy n characters from source
call_user_func($callback, 'c', $from, $from_offset, $n, '');
$from_offset += $n;
}
// ...
I guess your class’s FQCN is
Sopos\WikiBundle\Services\FineDiff, so the callback must be one these:You could also replace
__NAMESPACE__by the real namespace.