# PHP for TypeScript Developers

[Original page](https://codewithphp.com/series/php-typescript-developers/)

> Bridge your TypeScript expertise to PHP—learn modern PHP through the lens of familiar TypeScript concepts and best practices.

# PHP for TypeScript Developers


## Overview

Coming from TypeScript? You already have the mindset for modern PHP. This series bridges your existing knowledge to PHP 8.3+, highlighting parallels and differences between the ecosystems while teaching you idiomatic PHP.

## What You'll Learn

- **Type Systems**: How PHP's type system compares to TypeScript's
- **Modern Syntax**: Arrow functions, nullish coalescing, spread operators—PHP has them too
- **Package Management**: From npm to Composer
- **Async Patterns**: Promises vs PHP's async approaches
- **Tooling**: The PHP equivalents of your favorite TypeScript tools
- **Frameworks**: From Express/Nest.js to Laravel
- **Testing**: Jest → PHPUnit, testing patterns that feel familiar

## Prerequisites

This series assumes you:

- ✅ Have professional TypeScript/JavaScript experience
- ✅ Understand modern ES6+ features
- ✅ Are familiar with async/await and promises
- ✅ Have used npm and package.json
- ✅ Know OOP concepts (classes, interfaces, inheritance)

## What You'll Build

Throughout this series, you'll build:

1. **REST API** - Compare Express.js patterns to PHP implementations
2. **Type-Safe Models** - Leverage PHP's type system like TypeScript interfaces
3. **CLI Tool** - Node scripts vs PHP CLI applications
4. **Real-time Features** - WebSockets and async in PHP
5. **Full-Stack App** - Laravel application with TypeScript concepts

## Time Commitment

- **15 chapters** total
- **~45 minutes** per chapter
- **~12 hours** to complete the series
- **Hands-on exercises** in each chapter

## Learning Path

```
TypeScript Foundations → PHP Basics → Advanced Patterns → Full-Stack Integration
```

### Phase 1: Syntax & Types (Chapters 1-5)

Translate your TypeScript knowledge to PHP syntax and typing

### Phase 2: Ecosystem & Tools (Chapters 6-10)

Navigate PHP's package management, testing, and tooling

### Phase 3: Frameworks & Patterns (Chapters 11-15)

Build production-ready applications with Laravel

## Why PHP?

If you're wondering why learn PHP:

- **Market Demand**: PHP powers 77% of the web (WordPress, Laravel, Symfony)
- **Modern Language**: PHP 8+ rivals TypeScript in features
- **Performance**: PHP 8.3 is faster than Node.js in many benchmarks
- **Career Growth**: Combine TypeScript + PHP = full-stack powerhouse
- **Laravel**: One of the most elegant frameworks in any language

## Quick Start

### 1. Install PHP

**macOS** (using Homebrew):

```bash
brew install php
```

**Windows** (using Chocolatey):

```bash
choco install php
```

**Linux** (Ubuntu/Debian):

```bash
sudo apt update
sudo apt install php8.3-cli php8.3-mbstring php8.3-xml php8.3-curl
```

### 2. Verify Installation

```bash
php -v
# Should show PHP 8.3+ (similar to node --version)
```

### 3. Install Composer

Composer is PHP's npm. Install from [getcomposer.org](https://getcomposer.org/)

```bash
composer --version
# Similar to npm --version
```

### 4. Your First PHP Script

Create `hello.php`:

```php
<?php
// Like TypeScript, modern PHP supports strict typing
declare(strict_types=1);

// Arrow functions (like TypeScript)
$greet = fn(string $name): string => "Hello, {$name}!";

// Type-safe output
echo $greet("TypeScript Developer");
```

Run it:

```bash
php hello.php
```

## Chapter Overview

### 🎯 Part 1: Foundations

1. **TypeScript to PHP: Type Systems Compared** - Map your type knowledge
2. **Modern PHP Syntax for TS Developers** - Familiar patterns, new syntax
3. **Functions & Closures: From JS to PHP** - Arrow functions and more
4. **OOP: Classes, Interfaces & Generics** - Similar concepts, different syntax
5. **Error Handling: Try/Catch & Type Safety** - Beyond TypeScript's errors

### 📦 Part 2: Ecosystem

6. **Package Management: npm vs Composer** - Dependencies the PHP way
7. **Testing: Jest Patterns in PHPUnit** - Familiar testing approaches
8. **Code Quality: ESLint meets PHP_CodeSniffer** - Linting and formatting
9. **Build Tools: TypeScript Compiler vs PHP** - No compilation needed (mostly)
10. **Debugging: Node Inspector vs Xdebug** - Debugging tools and techniques

### 🚀 Part 3: Advanced & Frameworks

11. **Async in PHP: Promises vs Fibers** - Concurrency patterns
12. **REST APIs: Express.js vs PHP Native** - Build APIs without frameworks
13. **Laravel Foundations: The PHP Framework** - Like Nest.js, but PHP
14. **Database & ORMs: TypeORM meets Eloquent** - Type-safe queries
15. **Full-Stack: Inertia.js (React/Vue + Laravel)** - Best of both worlds

## Comparison: TypeScript vs PHP

For a side-by-side look at checking data at runtime, read [PHP vs TypeScript](/compare/php-vs-typescript/).

| Feature                | TypeScript                                  | PHP 8.3+                               |
| ---------------------- | ------------------------------------------- | -------------------------------------- |
| **Type System**        | Static (compile-time)                       | Static (runtime checked)               |
| **Nullability**        | `string \| null`                            | `?string`                              |
| **Union Types**        | `string \| number`                          | `string\|int`                          |
| **Interfaces**         | `interface User {}`                         | `interface User {}`                    |
| **Enums**              | `enum Status {}`                            | `enum Status {}`                       |
| **Async**              | `async/await`                               | Fibers, Promises (via libraries)       |
| **Package Manager**    | npm/yarn/pnpm                               | Composer                               |
| **Runtime**            | Node.js/Deno/Bun                            | PHP-FPM, CLI                           |
| **Arrow Functions**    | `(x) => x * 2`                              | `fn($x) => $x * 2`                     |
| **Spread Operator**    | `...array`                                  | `...$array`                            |
| **Null Coalescing**    | `??`                                        | `??`                                   |
| **Optional Chaining**  | `?.`                                        | `?->`                                  |
| **String Templates**   | `` `Hello ${name}` ``                       | `"Hello {$name}"`                      |
| **Destructuring**      | `const {a, b} = obj`                        | `['a' => $a, 'b' => $b] = $arr`        |
| **Named Arguments**    | Object parameters                           | Native: `func(name: 'value')`          |
| **Type Inference**     | Strong                                      | Limited                                |
| **Generics**           | `Array<T>`                                  | `array<T>` (via PHPStan/Psalm)         |
| **Readonly**           | `readonly` modifier                         | `readonly` (PHP 8.1+)                  |
| **Strict Null Checks** | Via `strictNullChecks`                      | Via `declare(strict_types=1)`          |
| **Module System**      | ES Modules, CommonJS                        | Namespaces, PSR-4 autoloading          |
| **Decorators**         | Experimental `@decorator`                   | Attributes `#[Route('/api')]`          |
| **Testing**            | Jest, Vitest, Playwright                    | PHPUnit, Pest, Codeception             |
| **Linting**            | ESLint, Biome                               | PHP_CodeSniffer, PHPStan, Psalm        |
| **Formatting**         | Prettier, Biome                             | PHP-CS-Fixer, Laravel Pint             |
| **Hot Reload**         | Vite, Webpack HMR                           | Laravel Mix, Vite Laravel plugin       |
| **Popular Frameworks** | Express, Nest.js, Next.js, Nuxt            | Laravel, Symfony, Slim                 |
| **ORM**                | TypeORM, Prisma, Drizzle                    | Eloquent (Laravel), Doctrine (Symfony) |
| **Deployment**         | Vercel, Netlify, PM2                        | Laravel Forge, Vapor, traditional LAMP |

## Code Examples Repository

All code examples for this series are available in the `/code/php-typescript-developers/` directory.

Each chapter includes:

- ✅ **Side-by-side comparisons** (TypeScript vs PHP)
- ✅ **Runnable examples** with setup instructions
- ✅ **Migration guides** for common patterns
- ✅ **Composer dependencies** (`composer.json`)
- ✅ **README documentation** for each chapter

## Community & Support

**Questions?** Open an issue on [GitHub](https://github.com/dalehurley/codewithphp)

**Found a bug?** Pull requests welcome!

## Next Steps

Ready to start? Head to [Chapter 1: TypeScript to PHP - Type Systems Compared](/series/php-typescript-developers/chapters/01-type-systems-compared)

---

**Last Updated**: November 2025
**PHP Version**: 8.3+
**Difficulty**: Intermediate
**Estimated Time**: 12 hours
