Note: lines in file start from 1!
Sample to get class code:
<?php
$class = new ReflectionClass('Foo');
$offset = $class->getStartLine() - 1;
$code = implode(
'',
array_slice(
file($class->getFileName()),
$offset,
$class->getEndLine() - $offset
)
);
?>