开发者

php compiler to compare code?

We have a codebas开发者_运维百科e of php scripts that we want to convert to a new coding convention. We are looking at automated beautifying to convert scripts to the new standard. We'd like to make double sure that the code still works as it originally did. We can use php -l on the command line to make sure that there are no errors, but we'd like to go to the next step to make sure that the old formatted is functionally the same as the new.

Is there a way we can compile binaries or whatever from both the old and the new to ensure that they are identical? I'm assuming that indentation, line breaks, etc are ignored in a compiled form?


You can compare the php bytecode with bytekit-cli (blogpost) / (github project).

To see if your new and old code produces the same php-bytecode. Knowing that you can be pretty sure everything will work. (If you are using annotations i'm not to sure how that works out with that)


Call token_get_all on the old and the new script and compare the results taking your changes (added/removed spaces, tabs, curly braces, even comments and commata at certain places) into account.


I would suggest using phc. Parse each file and produce XML output, and compare the XML output before and after.

phc --dump-xml filename.php

Of course, part of the problem might be that your beautifier does not use a real parser, and so can be faulty (I don't know, I haven't looked at it). phc has a --pretty-print option that is based on a real parser, so you might have better luck with it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜