4

I have managed to code a feature which takes my entire library's many .php files, bake them into a single PHP file, then removes all code comments and blankspaces. That part works perfectly and the result is a messy, single PHP file.

However, all the function names, variable names and constants (also classes and whatnot) are still intact. I use extremely descriptive ones because it helps me code:

<?php

    $customer_total_account_balance = accounts_fetch_balance_for_account_id(4252392533521);

I want this to be come:

<?php

    $a = b(4252392533521);

I have seen this for JavaScript (Closure Compiler, UglifyJS, etc.), but not for PHP. That is, excluding payware solutions and "online toolz", AKA a webpage where somebody has coded a black box on their server to do this. I need it to be actual code which I can read and verify that it does its job, and only its job, and run it locally on Windows.

I will not attempt to code this on my own. It's a can of worms of problems. I have tried many times in the past but always got stuck because it's not trivial. It must of course not introduce bugs and issues with the code!

The fact that it only has to work on a single PHP file should make it more likely that it does exist, though.

The purpose of this is to be able to put code of "private nature" on untrusted/shared servers, making the impact of somebody reading or copying it far less problematic than if they had also got the full dir/file structure, all the code comments, all the whitespace intact and of course all the identifiers.

1
  • 1
    It seems to me that what you're trying to do is obfuscation of your code. I don't have experience with obfuscating PHP code, but just Googling for obfuscate php gives some results, some of which are free / open source. This article lists five options, perhaps you should give them a try and see which one suits you best. – Glorfindel Mar 8 '20 at 13:33
1

You may give a try on this active library: Yak PRO PHP Obfuscator since it will run on php >= 7.0 (also available old version for php 5.3, etc)

Very powerful if you know what you're doing, you can begin with a limited set of options and explicitly do what you're asking about changing (obfuscating) function names, among other common techniques to make your code "unreadable".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.