1. Home
  2. PHP Sandbox

PHP Sandbox

Write PHP, press Run, see the output. Seven real PHP versions from 7.4 to 8.5, running privately in your browser.

main.php
<?php
// Write PHP here and press Run (or Cmd/Ctrl + Enter).
$versions = ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5'];

echo "Running PHP " . PHP_VERSION . PHP_EOL;

$supported = array_filter(
    $versions,
    fn(string $v) => version_compare($v, '8.2', '>=')
);

echo "Supported branches: " . implode(', ', $supported) . PHP_EOL;
printf("Peak memory: %.1f KB\n", memory_get_peak_usage() / 1024);
OutputPHP 8.4.25
Press Run or ⌘/Ctrl + Enter. The first run downloads PHP (about 5 MB) and takes a few seconds; after that it is instant.

Tip: switch versions and press Run again to compare behaviour. ⌘/Ctrl + Enter runs the code.

A sandbox that runs on your machine

Most online PHP sandboxes send your code to a server, run it in a container and send the output back. This one ships the PHP interpreter to you instead.

Real PHP, not an emulation

Each version is built from the official php-src code and compiled to WebAssembly. Output, warnings and error messages are exactly what php prints on a server.

Seven versions side by side

Run the same snippet on 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 and 8.5. It is the fastest way to see what an upgrade changes before you touch production.

Private by design

Code never leaves your browser. There is no account, no saved history on our side and nothing to delete afterwards.

Instant after the first run

No queue, no cold start on a shared server. Once a version is cached, a typical snippet finishes in a few milliseconds.

Shareable links

Press Share to copy a link that opens your code and version. The snippet is compressed into the link itself, so nothing is stored anywhere.

Errors you can read

Fatal errors, warnings and deprecations are colour-coded, and the line that caused a fatal error is highlighted in the editor.

Try what is new in recent PHP versions

Each example opens in the sandbox with the right version selected. Switch to an older version to see the error it would cause.

Pipe operator

PHP 8.5+

PHP 8.5 passes a value through a chain of callables from left to right.

<?php
$slug = ' Hello PHP World '
    |> trim(...)
    |> strtolower(...)
    |> (fn($s) => str_replace(' ', '-', $s));

echo $slug; // hello-php-world
Open in the sandbox →

Property hooks

PHP 8.4+

PHP 8.4 lets a property define its own get and set logic, no boilerplate getters needed.

<?php
class User
{
    public string $email {
        set => strtolower(trim($value));
    }

    public string $domain {
        get => substr($this->email, strpos($this->email, '@') + 1);
    }
}

$u = new User();
$u->email = '  Ada@Example.COM ';
echo $u->email, PHP_EOL;  // ada@example.com
echo $u->domain, PHP_EOL; // example.com
Open in the sandbox →

Typed class constants

PHP 8.3+

PHP 8.3 adds types to class constants and the json_validate() function.

<?php
interface HasVersion
{
    const string VERSION = '1.0';
}

class Api implements HasVersion
{
    const string VERSION = '2.0';
}

echo Api::VERSION, PHP_EOL;
var_dump(json_validate('{"ok": true}'));
var_dump(json_validate('{ok: true}'));
Open in the sandbox →

Readonly classes

PHP 8.2+

Mark a whole class readonly in PHP 8.2. Writing a property after construction throws an Error.

<?php
readonly class Point
{
    public function __construct(
        public int $x,
        public int $y,
    ) {}
}

$p = new Point(3, 4);
echo "($p->x, $p->y)", PHP_EOL;

try {
    $p->x = 10;
} catch (Error $e) {
    echo get_class($e), ': ', $e->getMessage(), PHP_EOL;
}
Open in the sandbox →

What works in the sandbox

The sandbox is a complete PHP runtime, so the whole core language works: classes, interfaces, traits, enums, closures, generators, fibers, exceptions, references and the standard library of string, array, math and date functions. Common extensions are built in, including json, mbstring, ctype, bcmath, dom, simplexml, xml, pcre, zlib, zip, gd, openssl, sqlite3 and pdo_sqlite. Run print_r(get_loaded_extensions()); to see the full list for the version you picked.

Each run starts from a clean state. Variables, files and classes from the previous run are gone, which keeps results predictable. Scripts are stopped after 10 seconds, which protects your browser tab from an accidental infinite loop.

What does not work

  • Network access. Outgoing HTTP requests, sockets, email and connections to MySQL or PostgreSQL servers are not possible from a browser sandbox.
  • Your own files and Composer packages. You cannot require a vendor folder. Paste the classes you need into the editor instead.
  • Some extensions. intl, imagick, redis, mysqli and pdo_mysql are not loaded. The curl functions exist but cannot reach the network.
  • Server variables. There is no real web request, so $_GET, $_POST and most of $_SERVER are empty.

When to use a sandbox and when to install PHP

A sandbox is ideal for quick questions: how does array_splice behave with negative offsets, what does this regular expression match, does my snippet still work on PHP 8.4, why does this date format print what it prints. It is also the easiest way to show someone a problem, because a share link reproduces it exactly.

Install PHP locally, or use Docker, when you work on a real project: anything with Composer dependencies, a database, a framework like Laravel or Symfony, or a test suite. On macOS, brew install php gives you the latest version. On Ubuntu and Debian, the ppa:ondrej/php and packages.sury.org repositories provide every supported version. On Windows, download the zip from windows.php.net or use WSL.

Not sure your code runs on an older server? The PHP Version Checker runs a snippet on all seven versions at once and tells you the minimum version it needs, and the PHP Syntax Checker finds parse errors without running anything.

Frequently asked questions

What is a PHP sandbox?

A PHP sandbox is an isolated place to run PHP code without installing anything or touching a real server. This one runs the official PHP interpreter compiled to WebAssembly inside your browser tab, so the code is fully separated from your computer's files and from our servers.

Which PHP versions can I run?

Seven versions: 8.5.10, 8.4.25, 8.3.33, 8.2.33, 8.1.34, 8.0.30, 7.4.33. Pick one with the version switcher above the editor. Switching versions is a quick way to see how the same code behaves before and after an upgrade.

Is the code I type private?

Yes. Your code runs locally in your browser and is never sent to us. Share links store the code in the part of the URL after #, which browsers do not send to servers, so even a shared snippet never reaches our logs.

Can I connect to a database or call an API?

No. A browser sandbox has no outgoing network access, so curl, file_get_contents('https://…') and MySQL connections do not work. SQLite does work, because the database lives in memory inside the sandbox. For network code, use a local install or a container.

Why does the first run take a few seconds?

The first time you use a version, your browser downloads that PHP build (about 5 MB compressed). After that it stays in the browser cache, and runs start in milliseconds, even after you reload the page.

Is this the same as an online PHP compiler?

“Online PHP compiler” is the common name for the same thing. PHP is interpreted rather than compiled ahead of time, but the result is identical: you write code, press Run and see the output. The difference here is that execution happens on your own device instead of a remote server, so there is no queue and no rate limit.