PHP Playground
Experiment with PHP snippets in your browser — stdout, problems and request stubs.
PHP code
empty · PHP 8.3Result
Exit: 0 · 0 steps · 0 problemsEnter PHP code to run it
Load an example to see strings, arrays, foreach or a parse error.
Details
PHP Playground interprets a small, zero-dependency subset of PHP locally. Supported: echo/print, double-quoted interpolation (including {$var} forms), scalar arithmetic (+ - * / % **), comparison operators, if/elseif/else, while, for, foreach over indexed and associative arrays, array appends, sprintf/printf formatting with flags, width and precision, count, strlen, strtoupper, strtolower, trim, implode, str_repeat, round, json_encode, preg_replace, var_dump, print_r, die/exit, throw and PHP_EOL-like constants. $_GET and $_POST can be filled with JSON stubs, diagnostics carry line numbers for parse errors, fatal errors, warnings and notices, and a version selector labels the syntax profile from 7.4 through 8.3. This is a lightweight simulator, not php-wasm: functions, classes, switch, try/catch and other unlisted constructs are reported as diagnostics and skipped, there are no extensions, no database, no network, no filesystem and no ini engine, and a 2,000-step budget bounds loops.
More examples
Strings
$name = "Ada";
echo "Hello, $name!\n";Assigns a scalar and interpolates it into a double-quoted string with a newline escape.
Arrays and foreach
$ages = ["Ana" => 31, "Bo" => 28];
foreach ($ages as $name => $age) {
echo "$name is $age\n";
}Builds an associative array and iterates key/value pairs with the foreach subset.
Parse error
echo "unclosed;
if (true) {Unbalanced braces produce a parse error with the failing line number in the Problems tab.
Examples
Interpolation
$name = "Ada"; echo "Hello, $name!";Hello, Ada!Double-quoted strings interpolate scalar variables.
Associative foreach
foreach (["Ana" => 31] as $name => $age) { echo "$name=$age"; }Ana=31The key and value form of foreach is supported for arrays and maps.
Parse error
echo "ok";
if (true) {Line 2: Parse error: braces are unbalancedUnbalanced braces are detected before any statement executes.
About this tool
PHP Playground runs a documented subset of PHP directly in your browser. Write a snippet, choose a syntax profile from PHP 7.4 to 8.3, optionally fill $_GET and $_POST with JSON stubs, and read the output next to a line-mapped problem list. Code is never uploaded.
The supported surface concentrates on the idioms used in short experiments: echo and print, double-quoted interpolation, scalar operators and concatenation, indexed and associative arrays, foreach, if, while with a step budget, and helpers such as count, implode, sprintf, json_encode and preg_replace. Undefined variables become notices rather than fatal errors, so a run keeps going and reports what happened.
Parse errors are detected before execution; fatal errors, warnings and notices carry 1-based line numbers. The report download includes both the captured output and the diagnostics, with the exit code and step count, so a failing snippet can be pasted into an issue or a chat without losing context.
This is not php-wasm. There are no PHP extensions, no database drivers, no network, no host filesystem and no ini engine. The version selector labels the syntax profile rather than downloading a runtime, and unsupported functions produce an explicit warning. The UI says this before the first run.
What this tool does not do
- This is a subset interpreter, not a PHP binary or php-wasm build.
- No extensions, include statements, namespaces, classes, database drivers, sockets or real filesystem access.
- Else branches and match expressions are outside the supported control-flow subset.
- Output is limited to the 2,000-step budget and a small in-memory buffer.
- Diagnostics mimic PHP wording but are produced by the local parser, not by php -l.
How to use this tool
Write PHP
Type code with or without <?php tags, or load one of the example chips.
Choose a profile
Select a version from 7.4 to 8.3. The badge describes the syntax profile; no runtime download happens.
Stub the request
Put JSON objects in the $_GET and $_POST fields when your snippet reads superglobals. Invalid JSON is treated as empty.
Run and inspect
Output updates as you type. Switch to Problems to see parse errors, fatals, warnings and notices with line numbers.
Export
Copy the visible panel or download the full report with output, diagnostics, exit code and step count.
Use cases
Syntax checks
Confirm the shape of a snippet before pasting it into a larger application.
Teaching
Show interpolation, arrays and control flow with immediate visible output.
Request handling
Exercise superglobal-reading code with predictable $_GET and $_POST stubs.
Bug reports
Download a report containing output, diagnostics and line numbers for a minimal reproduction.
Supported constructs
| Group | Examples |
|---|---|
| Output | echo, print |
| Scalars | $n = 2; $n .= "x"; |
| Arrays | [1, 2], ["a" => 1] |
| Control | if, foreach, while |
| Helpers | sprintf, json_encode, preg_replace |
| Request | $_GET["name"] |
Unsupported statements are reported as warnings rather than silently ignored.
Common mistakes
Mistake:Expecting extensions such as mysqli or curl.
Fix:They are unavailable; use a local PHP installation for extension-dependent code.
Mistake:Using else branches.
Fix:The subset handles if and loop blocks; restructure the example into separate conditions.
Mistake:Writing a class to test OOP.
Fix:Classes, traits, interfaces and namespaces are reported as unsupported.
Mistake:Passing a JSON array to $_GET.
Fix:Stub editors expect flat JSON objects; other shapes are treated as empty.
Mistake:Assuming the version selector downloads PHP 8.3.
Fix:It labels a syntax profile only; the same local subset runs for every version.
Frequently asked questions
Which PHP versions are supported?
The version selector offers syntax profiles for 7.4, 8.0, 8.1, 8.2 and 8.3, with 8.3 as the default. It does not download or run those PHP binaries — the same small local interpreter handles every profile. Use the badge as a label for the syntax you are targeting, and run version-specific behaviour in a real PHP installation.
Are extensions like mysqli or curl available?
No. There are no extensions, no database drivers, no filesystem access and no network. Functions outside a small whitelist produce a warning on the Problems tab. This keeps the tool fast and makes it honest about what it can verify.
How do I test code that reads $_GET or $_POST?
Fill the corresponding stub field with a flat JSON object, for example {"name":"Ada"}. Values are injected before execution and read through normal superglobal syntax. Invalid JSON is treated as an empty array rather than an error.
What happens when my code has a parse error?
Unbalanced braces are detected before execution, and the Problems tab shows a parse error with the 1-based line number. Output produced before a fatal error is kept in the Output tab, so you can see how far the script got.
Why does my class definition not work?
Classes, interfaces, traits and namespaces are outside the supported subset and are reported in the warning list. The tool focuses on procedural snippets, arrays, strings and simple control flow. Use a local PHP runtime for object-oriented code.
How are runaway loops handled?
Each executed statement consumes one step from a 2,000-step budget. Exceeding it ends the run with exit code 124 and a fatal diagnostic, so a while(true) loop cannot freeze your tab. The same guard applies to nested loops.
Is my PHP code uploaded?
No. Parsing and execution happen entirely in the browser tab, and the draft is stored in localStorage so a reload does not lose it. The report download is generated locally; there is no server request or telemetry on code contents.
References & standards
Related tools
AssemblyScript Playground
Write AssemblyScript-style functions, inspect a module preview, and run exports with a step-bounded offline evaluator.
Bash Playground
Test bash script snippets in a local mini-shell with seeded files, stdin, stream tags and visible sandbox limits.
C & C++ Playground
Check C and small C++ source for structural problems, map findings to lines and see the compile command for a local toolchain.
C# Playground & Snippet Checker
Static pre-flight checks for C# snippets — diagnostics, detected features and metrics, entirely in-browser.
Dart Playground
Write Dart, press Run, and see print output in your browser.
DBML Playground
Write DBML and see an ER diagram plus SQL DDL for Postgres, MySQL, SQLite and MSSQL, all in your browser.