Simple PHP Editor Online
<?php
function nfact($n) {
if ($n == 0) {
return 1;
}
else {
return $n * nfact($n - 1);
}
}
echo "\n\nPlease enter a whole number ... ";
$num = trim(fgets(STDIN));
// ===== PROCESS - Determing the factorial of the input number =====
$output = "\n\nFactorial " . $num . " = " . nfact($num) . "\n\n";
echo $output;
?>
About This PHP Editor
PHP runs a large share of the web, from WordPress to Laravel to Wikipedia's MediaWiki. Its reputation is stuck somewhere around 2009; PHP 8 has typed properties, enums, union types, named arguments, attributes and a JIT, and modern PHP looks very little like the code that gave it that reputation.
The editor highlights PHP tags, variables, heredocs and the HTML that surrounds them, which is the part most editors get wrong.
PHP 8 syntax worth knowing
| Syntax | What it does |
|---|---|
function f(int $a, ?string $b = null): array |
Parameter and return types, with a nullable type marked by ?. |
public function __construct(private int $id) {} |
Constructor property promotion - declares and assigns in one place. |
enum Status: string { case Draft = "draft"; } |
Backed enum. Replaces class constants for fixed sets of values. |
$name = $user?->profile?->name ?? "Anon"; |
Nullsafe operator plus null coalescing. |
match ($code) { 200, 201 => "ok", default => "err" }; |
match is an expression, uses strict comparison, and does not fall through. |
f(limit: 10, offset: 0) |
Named arguments - order no longer matters. |
$fn = fn ($x) => $x * $multiplier; |
Arrow function; captures the outer scope automatically. |
[$a, $b] = $array; |
Array destructuring, including nested and keyed forms. |
Long-standing traps
- Loose comparison.
==still coerces. PHP 8 fixed the worst case -0 == "foo"is now false - but===remains the right default. - Arrays are one type doing two jobs. A PHP array is an ordered hash map, so it serves as both list and dictionary.
array_values()after afilteris often needed to get sequential keys back. - References in foreach.
foreach ($a as &$v)leaves$vbound after the loop, and the next foreach over the same variable corrupts the last element. Alwaysunset($v)afterwards. - Never unserialize untrusted input. PHP object injection is a real and exploited vulnerability class. Use JSON across any trust boundary.
- String functions and multibyte text.
strlen()counts bytes, not characters. Use themb_family for anything that might not be ASCII.
Your Code Never Leaves Your Browser
The editor is JavaScript running in this tab. Nothing you type is posted to a server, stored, logged or associated with you, and there is no account and no autosave. That makes it safe to paste a snippet from a private codebase in order to read it with highlighting. The trade-off is that nothing persists either — refresh the page and your content is gone, so copy anything you want to keep.
Frequently Asked Questions
Can this editor run PHP code?
No - PHP executes on a server, and this page has no runtime attached. It is for reading, formatting and checking a snippet. To run code, use a local PHP installation or a container.
Is PHP still worth learning?
It powers a very large share of existing web software, so the maintenance market alone is substantial, and modern frameworks like Laravel and Symfony are productive and well engineered. PHP 8 is a genuinely different language from PHP 5.
What is the difference between == and === in PHP?
=== compares value and type with no conversion. == converts first, which produces surprises across types. Use === unless you have a specific reason to want coercion.
Editors for Other Languages
Same editor, configured for a different language, each with its own syntax reference.