Get PHP Opcodes Dynamically at Runtime
You could use parsekit
which is available through pecl which can be downloaded from the pecl website or installed with:
sudo pecl install parsekit
Get OPcodes from a string of PHP code during runtime:
You could use the parsekit_compile_string
The syntax for this command is:
array parsekit_compile_string ( string $phpcode [, array &$errors [, int $options = PARSEKIT_QUIET ]] )
Parameters:
phpcode
A string containing phpcode. Similar to the argument to eval().
errors
A 2D hash of errors (including fatal errors) encountered during compilation. Returned by reference.
options
One of either PARSEKIT_QUIET or PARSEKIT_SIMPLE. To produce varying degrees of verbosity in the returned output.
Return Values
Returns a complex multi-layer array structure as detailed below.
An example usage of this is:
<?php $ops = parsekit_compile_string('echo "Foo\n";', $errors, PARSEKIT_QUIET); var_dump($ops);?>
The output is too long to include in this answer but is available on the documentation page
Get OPcodes from a PHP file during runtime:
You could use the parsekit_compile_file
Very similar to the above approach but parses a file instead of a string.