Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A command-line tool built on the PHP Bytekit extension.
PHP Shell
Tag: 1.1.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Bytekit
examples
README.markdown
bytekit.bat
bytekit.php
package.xml

README.markdown

bytekit-cli

Bytekit is a PHP extension that provides userspace access to the opcodes generated by PHP's compiler.

bytekit-cli is a command-line tool that leverages Bytekit to perform common code analysis tasks.

Installation

bytekit-cli should be installed using the PEAR Installer. This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0.

The PEAR channel (pear.phpunit.de) that is used to distribute bytekit-cli needs to be registered with the local PEAR environment:

sb@ubuntu ~ % pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:

sb@ubuntu ~ % pear install phpunit/bytekit
downloading bytekit-1.1.1.tgz ...
Starting to download bytekit-1.1.1.tgz (10,134 bytes)
.....done: 10,134 bytes
downloading File_Iterator-1.1.0.tgz ...
Starting to download File_Iterator-1.1.0.tgz (3,181 bytes)
...done: 3,181 bytes
install ok: channel://pear.phpunit.de/File_Iterator-1.1.0
install ok: channel://pear.phpunit.de/bytekit-1.1.1

After the installation you can find the bytekit-cli source files inside your local PEAR directory; the path is usually /usr/lib/php/Bytekit.

Usage Examples

Disassemble a source file:

sb@ubuntu bytekit-cli % bytekit /tmp/test.php
bytekit-cli 1.1.1 by Sebastian Bergmann.

Filename:           /tmp/test.php
Function:           main
Number of oplines:  13
Compiled variables: !0 = $a, !1 = $b, !2 = $c

  line  #     opcode                           result  operands
  -----------------------------------------------------------------------------
  2     0     EXT_STMT
        1     ASSIGN                                   !0, 1
  3     2     EXT_STMT
        3     ASSIGN                                   !1, 2
  4     4     EXT_STMT
        5     ADD                              ~2      !0, !1
        6     PRINT                            ~3      ~2
        7     FREE                                     ~3
  5     8     EXT_STMT
        9     JMPZ                                     !0, ->12

        10    ASSIGN                                   !2, 3
        11    JMP                                      ->12

  6     12    RETURN                                   1

Scan for unwanted mnemonics in a source tree and write a report in PMD-XML format:

sb@ubuntu ~ % bytekit --rule=DirectOutput \
                      --rule=DisallowedOpcodes:EVAL
                      --xml pmd-bytekit.xml
                      /usr/local/src/phpunit/trunk
bytekit-cli 1.1.1 by Sebastian Bergmann.

  - Disallowed opcode "EVAL"
    in /usr/local/src/phpunit/trunk/PHPUnit/TextUI/Command.php:177

  - Direct output of variable $buffer
    in /usr/local/src/phpunit/trunk/PHPUnit/TextUI/TestRunner.php:468

  - Direct output of variable $buffer
    in /usr/local/src/phpunit/trunk/PHPUnit/Util/Printer.php:173

  - Direct output of variable $message
    in /usr/local/src/phpunit/trunk/PHPUnit/Extensions/Database/UI/Mediums/Text.php:130

  - Disallowed opcode "EVAL"
    in /usr/local/src/phpunit/trunk/PHPUnit/Extensions/PhptTestCase.php:223

  - Disallowed opcode "EVAL"
    in /usr/local/src/phpunit/trunk/PHPUnit/Framework/TestCase.php:1158

  - Disallowed opcode "EVAL"
    in /usr/local/src/phpunit/trunk/PHPUnit/Framework/TestCase.php:1059

The report looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<pmd version="bytekit-cli 1.1.1">
  <file name="/usr/local/src/phpunit/trunk/PHPUnit/TextUI/Command.php">
    <violation rule="Disallowed opcode &quot;EVAL&quot;" line="177" class="PHPUnit_TextUI_Command" method="run"/>
  </file>
  <file name="/usr/local/src/phpunit/trunk/PHPUnit/TextUI/TestRunner.php">
    <violation rule="Direct output of variable $buffer" line="468" class="PHPUnit_TextUI_TestRunner" method="write"/>
  </file>
  <file name="/usr/local/src/phpunit/trunk/PHPUnit/Util/Printer.php">
    <violation rule="Direct output of variable $buffer" line="173" class="PHPUnit_Util_Printer" method="write"/>
  </file>
  <file name="/usr/local/src/phpunit/trunk/PHPUnit/Extensions/Database/UI/Mediums/Text.php">
    <violation rule="Direct output of variable $message" line="130" class="PHPUnit_Extensions_Database_UI_Mediums_Text" method="output"/>
  </file>
  <file name="/usr/local/src/phpunit/trunk/PHPUnit/Extensions/PhptTestCase.php">
    <violation rule="Disallowed opcode &quot;EVAL&quot;" line="223" class="PHPUnit_Extensions_PhptTestCase" method="run"/>
  </file>
  <file name="/usr/local/src/phpunit/trunk/PHPUnit/Framework/TestCase.php">
    <violation rule="Disallowed opcode &quot;EVAL&quot;" line="1158" class="PHPUnit_Framework_TestCase" method="getMockFromWsdl"/>
    <violation rule="Disallowed opcode &quot;EVAL&quot;" line="1059" class="PHPUnit_Framework_TestCase" method="getMock"/>
  </file>
</pmd>
Something went wrong with that request. Please try again.