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 pressCtrl+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.phpor virtual nested paths likeApp/Models/User.php,stubs/Vendor.stub, orvendor/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
- Multiple classes in a single file work automatically: You can place
User,Product,Order, an interface, and an enum inside a single tab likeModels.php, and call any of them fromindex.phpor any other tab without writingrequireorinclude. - Filenames do not need to match namespaces: A tab named
Models.phpcan declarenamespace App\Domain\Entities;, andindex.phpcan importuse App\Domain\Entities\User;immediately. - Virtual folders are optional: Naming a tab
Repositories/UserRepository.phpworks just as smoothly asUserRepository.php, and preserves the exact relative path in stack traces and Audit Reports. - Full TypePHP instrumentation across all tabs: Every non-vendor
.phptab is AST-transformed by TypePHP before execution, so interface inheritance, traits, generics, and zero line-drift stack traces work identically across files.
<?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 viarequire_oncebeforeindex.phpexecutes, 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_oncestill works: The working directory andinclude_pathpoint directly to the transformed workspace, so writingrequire_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 Pattern | Tab Badge | Playground Behavior |
|---|---|---|
*.stub or *.stub.php | stub | Automatically 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/... | vendor | Automatically 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 / Shortcut | Behavior |
|---|---|
Ctrl + Enter / Cmd + Enter | Runs the workspace starting from index.php. |
/** + Enter | Expands a full PSR-12 aligned DocBlock with your cursor on the middle * line. |
* ... + Enter | Continues the DocBlock with * and preserves inner indentation for multi-line array{ ... } shapes. |
*/ + Enter | Strips the 1-space DocBlock alignment so the next line aligns cleanly with class or function. |
PSR-12 Header + Enter | Pressing 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 Hover | Shows a compact declaration signature preview and clickable file:line badge for symbols across all open tabs. |
Ctrl + Click / Cmd + Click / F12 | Jumps directly to the declaring file tab, scrolls to the exact line, and briefly highlights the declaration. |
Ctrl + Space | Opens 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, oruse constsuggests fully qualified symbols from all open tabs. - Members (
->,?->,::): ResolvesTypePHP::facade methods,$this->/self::/static::scoped to the enclosing class, and$var->narrowed acrossextends,implements, anduse Traithierarchies 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@varinline 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
localStorageas 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.