Skip to content

Playground Guide ​

The TypePHP Playground is a full in-browser PHP 8.5 WebAssembly IDE running the real TypePHP runtime engine directly inside a browser Web Worker. Nothing is sent to a backend server for execution, and you can test single scripts, multi-file namespaces, stub overrides, SQLite queries, AST transformations, and Audit Mode reports with zero local installation.


Multi-File Workspaces & Tabs ​

The Playground supports multi-file projects through the horizontal file tab bar directly above the editor:

  • index.php (Entry Point): Always executes first when you click Run (or press Ctrl+Enter / Cmd+Enter). It stays pinned as the first tab and cannot be renamed or deleted.
  • Add Files (+ New File): Creates a new tab and immediately opens inline rename mode.
  • Rename Files: Double-click any non-entry tab to rename it. You can use flat filenames like Models.php or virtual nested paths like App/Models/User.php, stubs/Vendor.stub, or vendor/Acme/Legacy.php.
  • Delete Files (×): Removes a secondary tab and cleans it from the virtual filesystem on the next run.

Non-PSR-4 Classmap Autoloading (No require Needed) ​

In standard Composer projects, PSR-4 requires one class per file and matching directory paths for every namespace. To keep prototyping fast and frictionless, the Playground uses a zero-config classmap autoloader built with PHP's native \PhpToken::tokenize().

What This Means in Practice ​

  1. Multiple classes in a single file work automatically: You can place User, Product, Order, an interface, and an enum inside a single tab like Models.php, and call any of them from index.php or any other tab without writing require or include.
  2. Filenames do not need to match namespaces: A tab named Models.php can declare namespace App\Domain\Entities;, and index.php can import use App\Domain\Entities\User; immediately.
  3. Virtual folders are optional: Naming a tab Repositories/UserRepository.php works just as smoothly as UserRepository.php, and preserves the exact relative path in stack traces and Audit Reports.
  4. Full TypePHP instrumentation across all tabs: Every non-vendor .php tab is AST-transformed by TypePHP before execution, so interface inheritance, traits, generics, and zero line-drift stack traces work identically across files.
Multi-Class File & Function Helper Autoloading
<?php

declare(strict_types=1);

use App\Domain\User;
use App\Domain\Product;
use App\Domain\Collection;
use function App\Helpers\describeItem;

/** @var Collection<User> */
$users = new Collection();
$users->add(new User('Alice'));

echo describeItem($users->items[0]) . "\n\n";

echo "Adding Product into Collection<User>...\n";
$users->add(new Product('SKU-100'));

Standalone Functions & Top-Level Constants ​

PHP's native spl_autoload_register() only autoloads classes, interfaces, traits, and enums. It cannot autoload standalone functions or top-level constants.

To eliminate manual require boilerplate, the Playground scans every secondary .php tab during boot:

  • Standalone functions (function helper()) and top-level constants (const API_VERSION = 'v2';) are detected automatically and pre-loaded via require_once before index.php executes, similar to Composer's "autoload": { "files": [...] }.
  • Mixed files that contain both classes and standalone functions or constants also pre-load cleanly with zero duplicate declaration errors.
  • Explicit require_once still works: The working directory and include_path point directly to the transformed workspace, so writing require_once 'helpers.php'; resolves cleanly to the instrumented file.

Special File Conventions (.stub & vendor/) ​

Two filename conventions receive special treatment in the Playground so you can test advanced TypePHP architecture features in the browser:

File PatternTab BadgePlayground Behavior
*.stub or *.stub.phpstubAutomatically registered in TypePHP's stubs configuration. Not executed or added to the classmap, letting you override DocBlocks on other tabs. See the Stub Files Guide.
vendor/...vendorAutomatically excluded from AST transformation and left as raw native PHP, letting you test Vendor Isolation & Path Filtering.

Editor Ergonomics & Keyboard Shortcuts ​

The Playground editor (built on CodeMirror 6) includes tailored PHP and PHPDoc tooling:

Action / ShortcutBehavior
Ctrl + Enter / Cmd + EnterRuns the workspace starting from index.php.
/** + EnterExpands a full PSR-12 aligned DocBlock with your cursor on the middle * line.
* ... + EnterContinues the DocBlock with * and preserves inner indentation for multi-line array{ ... } shapes.
*/ + EnterStrips the 1-space DocBlock alignment so the next line aligns cleanly with class or function.
PSR-12 Header + EnterPressing Enter after class, interface, trait, enum, function, or a closing parameter ) keeps the cursor aligned for Allman { braces, and pressing Enter inside {} indents 4 spaces.
Format Code (Toolbar)Formats the active tab with 4-space PSR-12 indentation, aligned DocBlocks, nested array shapes, and PHP 8.5 `
Mouse HoverShows a compact declaration signature preview and clickable file:line badge for symbols across all open tabs.
Ctrl + Click / Cmd + Click / F12Jumps directly to the declaring file tab, scrolls to the exact line, and briefly highlights the declaration.
Ctrl + SpaceOpens autocomplete manually anywhere (including inside strings or comments).

Scope-Aware Cross-File Autocompletion ​

Autocomplete runs synchronously across all open tabs without interrupting typing inside strings or single-line comments:

  • Inside /** ... */ DocBlocks: Triggers immediately on @ for all TypePHP, @template-*, @phpstan-*, @psalm-*, and @typephp-* tags, plus refined types (positive-int, non-empty-string, list<>, array{}, key-of<>, int-mask-of<>) with automatic cursor placement inside brackets.
  • Imports: Typing use , use function , or use const suggests fully qualified symbols from all open tabs.
  • Members (->, ?->, ::): Resolves TypePHP:: facade methods, $this-> / self:: / static:: scoped to the enclosing class, and $var-> narrowed across extends, implements, and use Trait hierarchies in sibling tabs.
  • Variables ($): Strictly scoped to the active function, closure, or global scope so local parameters never leak into unrelated scopes.

Transformed Source, Config & Audit Reports ​

  • Source vs. Transformed Source: Switch to Transformed Source in the toolbar to inspect the exact zero line-drift PHP code emitted by TypePHP for whichever tab is currently selected. Toggle Eliminate Proven Checks inside Config to compare Compile-Time Check Elimination live.
  • Engine Configuration (Config): Toggle TypePHP enforcement ON/OFF, switch between Throw, Warn, and Report violation modes, test Full O(n) vs. Hybrid O(1) array validation, enable GDPR value redaction, or toggle individual @var inline variable categories.
  • Audit Report Viewer: When Report mode is active, violations appear in the Audit Report drawer tab with interactive diff cards, raw formatted JSON, one-click Copy JSON, and JSON file download. See Violation Reporting & Auditing.

Sharing & Reproducing Issues ​

  • Auto-Saved Drafts: Your tabs, active file, title, and engine settings are automatically persisted to localStorage as you type.
  • One-Click Share Links: Clicking the Share button generates a shortlink (https://typephp.dev/playground#r=...) that preserves every open tab, custom config setting, title, and report view mode (with an automatic compressed URL fallback #c=... if offline).
  • Bug Reports: If you encounter an edge case in TypePHP, create a minimal multi-file reproduction in the Playground, click Share, and paste the link directly into a GitHub Issue.