Menu

PHP Obfuscator Online – Free PHP Code Obfuscator

Scope-aware local variable renaming, string encoding with a matching runtime decoder, number literal obfuscation, and comment removal. Every output is re-checked for structural validity before display — invalid results are never reported as success.

Obfuscation Studio Free
Ready
PHP Source 0 lines • 0 chars
Obfuscated Output 0 lines • 0 chars
Obfuscation Options
All processing runs in your browser. Your code is never uploaded. Only transform code you own or have permission to modify.
Complete Guide to PHP Obfuscation

PHP obfuscation rewrites readable PHP into a form that is harder for humans and automated tools to understand, while preserving the exact runtime behaviour of the original program. This tool uses a real PHP tokenizer with scope analysis — not regular-expression guessing — to rename only the variables it can prove are safe to rename, and it structurally re-checks its own output before showing it to you.

Unlike compiled languages, PHP source usually ships as plain text on the server. Obfuscation raises the cost of casual inspection and copying for anyone who gains unintended read access to your files — it is a deterrent layered on top of proper server security, not a replacement for it.

What is PHP Obfuscation?

PHP obfuscation is the process of transforming a script into an equivalent script that is harder to read, modify, or reverse engineer. The output produces the same results, performs the same side effects, and depends on the same inputs as the original — only the names and surface form change, never the logic.

Because PHP commonly runs from plain .php files on shared hosting or inside deployed containers, anyone who gains filesystem access — through a misconfigured backup, a leaked repository, or a hosting panel — can read your source directly. Obfuscation raises the cost of understanding that logic; it does not make it impossible.

Techniques Used by This Tool

Scope-Aware Local Variable Renaming

The tokenizer locates every function and method body with a real { ... } block, and renames the $variables declared or used inside it — including inside nested closures — to short, meaningless names. Class properties, constants, method names, and anything referenced inside a string are left untouched.

String Encoding with Matching Decoder

Plain string literals are encoded as Base64 bytes XORed with a per-run key baked directly into a small decoder function prepended to your file. Strings that must remain compile-time constants — class constants, enum case values, parameter defaults — are automatically left as plain text, since PHP does not allow function calls there.

Integer Literal Obfuscation

Plain integer literals are rewritten as small arithmetic expressions, for example 100 becoming (172 - 72), so a quick visual scan of the file no longer reveals meaningful constants at a glance.

Comment Removal

The tokenizer strips //, #, and /* */ comments including docblocks, while correctly recognizing PHP 8 attribute syntax (#[Route(...)]) as code, not a comment, so framework attributes are never stripped by mistake.

How the Tool Works

  1. Tokenize. A hand-written PHP tokenizer splits the source into HTML passthrough regions, PHP open/close tags, identifiers, keywords, $variables, strings, heredoc/nowdoc blocks, numbers, attributes, comments, and punctuation.
  2. Find real function bodies. Every function/fn declaration with an actual { ... } block is located — interface signatures, abstract methods, and ambiguous arrow-function expressions are skipped entirely rather than risked.
  3. Exclude unsafe variables. Within each body, $this, PHP superglobals ($_GET, $_POST, $_SESSION, …), promoted constructor-property parameters, and any variable referenced inside a string or heredoc are excluded from renaming.
  4. Rename consistently. Every remaining $variable in that function's full range — including nested closures — is replaced with a fresh short name, used consistently everywhere it appears in that scope.
  5. Encode strings. Eligible string literals become calls to a decoder function with the key embedded inside the function itself, so decoding works correctly even when called from inside a class method (which does not inherit top-level script variables).
  6. Obfuscate numbers, strip comments, optionally minify. Integer literals are split into arithmetic, comments are removed, and whitespace is optionally collapsed.
  7. Reconstruct and validate. Tokens are re-emitted as source, then the tool re-tokenizes its own output and checks that every brace, parenthesis, bracket, and PHP tag balances before it is shown as a success.

Output Validation

Before displaying the result, the tool re-tokenizes the obfuscated output and performs a structural check: every { }, ( ), and [ ] must balance, and every <?php must close correctly. This catches the most common class of reconstruction error — a brace dropped during a transformation, for instance — before you ever see the output.

What is not validated: runtime behaviour equivalence or full PHP grammar correctness. The tool does not execute your code (that would be unsafe in a browser-based tool) and does not implement a complete PHP parser. Always run php -l and your test suite against the obfuscated file before deploying it.

What's Safe vs Unsafe to Rename

ConstructRenamed?Reason
Local variable inside a function/method bodyYesNot observable outside that scope
Function/method parametersYesBound at call time, local to the body
Variables inside a nested closureYesRenamed consistently across the whole outer scope, including the use(...) list
$thisNoReserved keyword-like reference to the current object
PHP superglobals ($_GET, $_SESSION, …)NoPredefined by the engine; renaming would disconnect them from real request data
Promoted constructor property parametersNoRenaming would also rename the class property it creates
Variable referenced inside a string or heredocNoInterpolated references can't be rewritten inside an opaque string token, so the name is kept everywhere to stay consistent
Class/object property names ($obj->name)NoProperty names have no $ sigil in PHP and are never tokenized as variables
Function, method, class, interface, and trait namesNoPublic API surface — renaming would break every call site and framework reflection
Namespaces and use importsNoMust match the autoloader and other files referencing them
Class constants and enum case valuesStrings left plainPHP requires compile-time constant expressions here; a decoder call isn't allowed

Use Cases

Self-Hosted / Licensed PHP Scripts

Scripts sold or licensed for self-hosting (plugins, themes, standalone tools) are distributed as readable PHP by default. Obfuscation discourages trivial copying of licensing checks and core logic.

WordPress & CMS Plugins

Obfuscate the production build of a commercial plugin or module before distributing it, while leaving hooks, filters, and class names intact so WordPress can still load it correctly.

Shared Hosting Deployments

On shared hosts where filesystem isolation between accounts isn't always perfect, obfuscating business logic adds a layer of protection beyond file permissions.

Internal Tooling & Scripts

Make internal automation scripts harder to casually modify or copy when they're shared more widely than intended, without changing how they're invoked.

Limitations & Legal

  • Not encryption. Obfuscation is reversible in principle. Never embed real secrets — API keys, database credentials, signing keys — and rely on obfuscation alone to protect them; use environment variables or a secrets manager instead.
  • Reflection-based code. Code that reads parameter or property names via ReflectionClass/ReflectionMethod, or that relies on get_class()/::class string matching for non-renamed identifiers, is unaffected since those names are never renamed by this tool — but always re-test reflection-heavy code after obfuscating.
  • Dynamic variable names. Code that builds variable names at runtime ($$name, variable variables) or reads them from extract()/compact() by string should have renaming disabled, since the tool cannot trace a string-built name back to a real variable.
  • Heredoc/nowdoc untouched. These blocks are intentionally left unobfuscated to avoid corrupting embedded variables and complex interpolation syntax.
  • Legal. Only obfuscate code you own or have rights to modify. Do not obfuscate open-source code in ways that violate its license (many open-source licenses require preserved attribution and readable source).

Related Obfuscators

Frequently Asked Questions

What is a PHP obfuscator?
A PHP obfuscator rewrites readable PHP into a form that is harder for humans to understand while keeping the exact same runtime behavior. Typical transformations include renaming local variables, encoding string literals, splitting number literals, and removing comments.
Is this PHP obfuscator free?
Yes. The tool is completely free with no registration, no file limits, and no hidden fees. All processing happens in your browser.
Does obfuscation break my PHP code?
This tool only renames variables it can prove are local to a single function or method body, including inside nested closures, and it never renames anything referenced inside a double-quoted string or heredoc. Class and object properties, constants, function and method names, and namespaces are never renamed, so public APIs keep working.
Is my code uploaded to your server?
No. The obfuscator runs entirely as JavaScript inside your browser. Your PHP source code never leaves your device.
Which PHP versions are supported?
The tokenizer understands PHP 7.4 through 8.3 syntax, including typed properties, constructor property promotion, enums, match expressions, arrow functions, named arguments, nullsafe operator, and PHP 8 attributes.
Can obfuscated PHP be reversed?
Obfuscation is a deterrent, not encryption. A determined attacker with PHP knowledge can often recover the logic. Never embed real secrets, such as production API keys or database passwords, in obfuscated source and rely on obfuscation alone to protect them.
Does obfuscation affect performance?
Runtime performance is essentially unchanged. String decoding runs once per string access through a tiny XOR loop, and minification can slightly reduce file size.
Will obfuscation break class properties or methods?
No. Only local variables inside function and method bodies are renamed. Property declarations, $this->property access, method names, class names, and constants are left exactly as written, since PHP resolves those by name at the object or class level, not by local scope.
Does this work with Laravel, Symfony, or WordPress?
It can obfuscate individual PHP files from any of these, but framework conventions (route closures, magic methods, reflection-based dependency injection, Blade/Twig templates) should be tested carefully afterward, since some frameworks rely on reading property or parameter names via reflection.
Does obfuscation break Composer autoloading?
No, as long as class, interface, trait, and namespace names are left unrenamed, which this tool always does. PSR-4 autoloading maps class names to file paths, and those names are never touched.
What does string encoding do?
Plain single-quoted and simple double-quoted string literals are encoded with a reversible byte-level XOR cipher plus Base64, and a tiny runtime decoder function is prepended to your file. This hides plain-text strings from casual inspection but does not provide cryptographic security.
Why are some strings not encoded?
Strings used inside class constants, enum case values, and function parameter default values must remain PHP constant expressions, so a function-call decoder cannot be used there. Interpolated double-quoted strings and heredoc/nowdoc blocks are also left untouched to avoid corrupting embedded variables.
Can I use this commercially?
Yes. You may obfuscate any code you own or have rights to modify and distribute the output under your own license.
Does it support PHP attributes like #[Route]?
Yes. The tokenizer recognizes PHP 8 attribute syntax (#[...]) and treats it as a single protected block, never confusing it with a # comment, so attributes used by frameworks for routing or validation are preserved exactly.
What identifiers are safe to rename?
Local variables declared or used inside a single function or method body, including its parameters and any nested closures, as long as they are not $this, a PHP superglobal, a promoted constructor property, or referenced inside a string.
Will it break constructor property promotion?
No. Parameters marked public, protected, private, or readonly in a constructor signature are detected and excluded from renaming, since renaming them would also rename the promoted class property they create.
What is the difference between obfuscation and minification?
Minification focuses on file size by collapsing whitespace. Obfuscation focuses on readability, making variable names and string contents hard to follow. This tool can do both at once.
Will it break heredoc or nowdoc strings?
Heredoc and nowdoc blocks are detected and passed through completely untouched by string encoding, and any variable referenced inside one is also excluded from renaming everywhere else in that scope, so the two always stay in agreement.
Does this tool insert antivirus triggers?
No. It does not inject suspicious patterns, delay loops, or self-modifying code of the kind associated with malware. A clear header banner is available to make the intent of the file obvious to anyone who opens it.
How is the output validated?
After transformation, the tool re-tokenizes its own output and checks that every brace, parenthesis, bracket, and PHP tag is balanced. If the structural check fails, the tool reports the failure rather than presenting broken code as a success.
Can obfuscation be detected?
Yes. Static analysis tools and experienced reviewers can usually tell PHP has been obfuscated, and some code-quality scanners flag it. Obfuscation is one layer of protection, not a security guarantee.

Conclusion

Obfuscation is one layer in a broader protection strategy. Combine it with server-side best practices (never shipping secrets in source, keeping dependencies patched, restricting filesystem access), proper licensing, and legal protections. This tool gives you honest obfuscation with structural output validation — not magic percentages or false claims of unbreakable security.