Skip to content

Allow exporting a reflection to PHP #133

@asgrim

Description

@asgrim

A pretty powerful feature of BR would be to export a reflection to PHP code (using PhpParser's printing functionality. This would pretty much take the whole AST stored within a reflection, feed it to PhpParser's printer, and return it.

Something like:

echo $reflectedClass->getMethod('add')->asPhp();

would result in a string with the following:

/**
 * Some addition method
 *
 * @param int $a
 * @param int $a
 * @return int
 */
private function add($a, $b)
{
    return $a + $b;
}

Note that because we exported the method only, it is not valid PHP by itself (it should exist within the context of a class).

Exporting a class would be more "complete":

echo $reflectedClass->asPhp();

might result in something like:

class MathematicalStuff
{
    /**
     * Some addition method
     *
     * @param int $a
     * @param int $a
     * @return int
     */
    public function add($a, $b)
    {
        return $a + $b;
    }
}

Note: not sure if the docblocks output is possible, but it would be great to include this

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions