Documentation

SourceBodyExtractor
in package

Source body extractor class

Recovers a method/function/closure's body as source text by slicing its declaring file between getStartLine()/getEndLine(). Both ReflectionMethod and ReflectionFunction extend ReflectionFunctionAbstract, so one helper serves MethodReflection and FunctionReflection, which previously each carried a near-identical, independently written copy of this logic.

Tags
category

Pop

author

Nick Sagona, III nick@popphp.org

copyright

Copyright (c) 2009-2026 Nick Sagona, III

license

https://www.popphp.org/license New BSD License

version
6.0.0

Table of Contents

Properties

$fileCache  : array<string, array<int, string>>
Cache of file() results, keyed by file path -- avoids re-reading and re-splitting the same source file once per method when a class with many methods is reflected.

Methods

extract()  : string|null
Extract a method/function's body as source text

Properties

$fileCache

Cache of file() results, keyed by file path -- avoids re-reading and re-splitting the same source file once per method when a class with many methods is reflected.

protected static array<string, array<int, string>> $fileCache = []

Methods

extract()

Extract a method/function's body as source text

public static extract(ReflectionFunctionAbstract $reflection, bool $stripBraces) : string|null
Parameters
$reflection : ReflectionFunctionAbstract
$stripBraces : bool
Return values
string|null

        
On this page

Search results