
PHP Basics Beginner
Overview
Welcome to Code with PHP — a comprehensive, hands-on course that takes you from absolute beginner to confident PHP developer. By the end of this series, you'll have built a complete blog application from scratch, understood how frameworks work under the hood, and be ready to tackle Laravel or Symfony with confidence.
PHP is one of the most widely-used programming languages in the world, powering everything from the smallest blogs to the largest social networks. Its gentle learning curve, massive community, and rich ecosystem of modern tools make it a fantastic first language for aspiring web developers.
Despite its long history, PHP is more relevant and powerful than ever. The language has evolved dramatically, embracing modern programming paradigms, strong typing, and a robust, professional toolchain. It is fast, flexible, and fun.
Who This Is For
This series is designed for:
- Complete beginners with no prior programming experience
- Developers transitioning from other languages (JavaScript, Python, Ruby, etc.)
- Self-taught developers who want to fill knowledge gaps and learn best practices
- Framework users who want to understand what happens "under the hood" in Laravel or Symfony
You don't need any previous programming knowledge — just basic computer skills, curiosity, and a willingness to type code and experiment.
Prerequisites
Software Requirements:
- PHP 8.4 (we'll show you how to install it in Chapter 00)
- Text editor or IDE (VS Code, PhpStorm, Sublime Text — any will work)
- Terminal/Command line access (built into macOS/Linux; we'll help Windows users too)
- SQLite (comes bundled with PHP)
PHP Version Compatibility
PHP 8.4 is recommended for the full learning experience. While most examples work on PHP 8.0+, some modern features require 8.4:
- Property hooks (Chapter 8): Requires PHP 8.4
- Asymmetric visibility (Chapter 8): Requires PHP 8.4
- Constructor property promotion: Works on PHP 8.0+
- Named arguments, match expressions: Work on PHP 8.0+
For the best experience and to future-proof your skills, install PHP 8.4.
Time Commitment:
- Estimated total: 20–30 hours to complete all chapters
- Per chapter: 30 minutes to 2 hours
- Projects (Chapters 18–19): 3–5 hours each
Skill Assumptions:
- You can create files and folders on your computer
- You're comfortable typing commands in a terminal
- You can install software
- No prior programming knowledge required
What You'll Build
By working through this series, you will create:
- Dozens of working scripts covering every core PHP concept
- A custom HTTP router that handles GET/POST requests and URL parameters
- A database-driven blog application with:
- Create, read, update, and delete (CRUD) operations
- User authentication and sessions
- Form handling and validation
- Secure database queries with PDO
- File uploads and management
- PSR-compliant code structure
- Your own MVC architecture from scratch, giving you deep insight into how frameworks work
- Two framework starter projects (Laravel and Symfony) to transition smoothly
Every code example is production-ready, following modern PHP 8.4 best practices and PSR standards.
Learning Objectives
By the end of this series, you will be able to:
- Write and execute PHP scripts confidently in development and production environments
- Master PHP fundamentals: variables, data types, operators, control structures, and functions
- Work with complex data using arrays, strings, and PHP's built-in functions
- Build object-oriented applications using classes, inheritance, traits, interfaces, and namespaces
- Handle errors gracefully with exceptions and custom error handling
- Manage dependencies professionally with Composer and autoloading
- Read and write files safely and efficiently
- Design and query databases using PDO with prepared statements
- Manage user state with sessions and cookies
- Build a custom HTTP router and understand request/response cycles
- Structure real applications with separation of concerns and MVC patterns
- Write clean, maintainable code following PSR-1 and PSR-12 standards
- Graduate confidently to Laravel or Symfony with deep foundational knowledge
How This Series Works
This series was designed with a simple philosophy: the best way to learn is by doing.
We will not just be reading about programming concepts; we will be applying them immediately. You'll type code, run it, break it, fix it, and build on it. Each chapter includes:
- Clear learning objectives so you know what to expect
- Step-by-step explanations with runnable code examples
- Hands-on exercises to reinforce concepts
- Troubleshooting tips for common errors
- Further reading for those who want to dive deeper
For the first 19 chapters, you will not touch a single framework. Instead, you'll learn the fundamental principles of the language, object-oriented programming, and modern tooling. You'll build your own router, your own application structure, and your own blog, piece by piece.
Why? Because understanding how a framework works under the hood is the key to mastering it.
By Chapter 20, when you finally encounter Laravel and Symfony, everything will click. You'll recognize the patterns, understand the abstractions, and be able to work confidently at any level of the stack.
TIP
Type the code yourself instead of copy-pasting. Muscle memory and debugging practice are crucial for becoming a confident developer.
Learning Path Overview
This diagram shows how concepts build on each other throughout the series:
┌─────────────────────────────────────────────────────────────┐
│ Part 1: Getting Started (Ch 00-01) │
│ • Environment Setup • Hello World │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Part 2: Core Fundamentals (Ch 02-07) │
│ • Variables & Types • Control Flow • Functions │
│ • Forms & Input • Arrays • Strings │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Part 3: Object-Oriented Programming (Ch 08-10) │
│ • Classes & Objects • Inheritance • Traits & Namespaces │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Part 4: Professional Development (Ch 11-16) │
│ • Exceptions • Composer • Files • Databases │
│ • Sessions & Cookies • PSR Standards │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Part 5: Real Applications (Ch 17-19) │
│ • HTTP Router • App Structure • Complete Blog Project │
└────────────────────────┬────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ Part 6: Frameworks & Beyond (Ch 20-23) │
│ • Laravel • Symfony • Next Steps • JSON & APIs │
└─────────────────────────────────────────────────────────────┘Each part builds essential skills you'll need for the next. By Part 5, you'll combine everything to build a complete application from scratch.
Quick Start
Want to jump in right now? Here's how to get your first PHP script running in under 5 minutes:
# 1. Check if PHP is installed (macOS/Linux have it by default)
php --version
# 2. Create a new directory and file
mkdir my-first-php && cd my-first-php
echo '<?php echo "Hello, PHP!";' > hello.php
# 3. Run your script
php hello.php
# Expected output: Hello, PHP!What's Next?
If that worked, you're ready to start! Head to Chapter 00 for proper setup, or continue to Chapter 01 to understand what just happened.
If you got an error, don't worry—Chapter 00 will walk you through installing PHP 8.4.
Chapters
Part 1: Getting Started (Chapters 00–01)
Set up your environment and write your first working PHP script.
00 — Setting Up Your Development Environment
Install PHP 8.4, configure your editor, and verify your setup. This chapter walks you through installing PHP on macOS, Linux, and Windows, choosing a text editor or IDE, and running your first verification script to ensure everything works correctly.
01 — Your First PHP Script
Write "Hello, World!" and understand how PHP executes. Learn about PHP tags, how to run scripts from the command line, basic output with echo and print, and get comfortable with PHP syntax from the very first line of code.
Part 2: Core Language Fundamentals (Chapters 02–07)
Master the building blocks: variables, control flow, functions, arrays, and strings.
02 — Variables, Data Types, and Constants
Learn PHP's type system and how to store data. Understand strings, integers, floats, booleans, arrays, and objects. Master variable naming conventions, type juggling, strict typing, and when to use constants versus variables.
03 — Control Structures
Make decisions with if/else, switch, and loops. Learn to control program flow with conditional statements, comparison and logical operators, switch statements for multiple conditions, and loops (for, foreach, while, do-while) for repetitive tasks.
04 — Understanding and Using Functions
Write reusable, modular code with functions. Master function syntax, parameters and arguments, return values, variable scope, type declarations, default parameters, variadic functions, and arrow functions for concise code.
05 — Handling HTML Forms and User Input
Process GET/POST requests and sanitize user data. Learn how PHP receives form data, the difference between GET and POST methods, how to validate and sanitize user input, and basic security practices to prevent common vulnerabilities.
06 — Deep Dive into Arrays
Work with indexed and associative arrays, plus powerful array functions. Master array creation, accessing and modifying elements, multidimensional arrays, array iteration, and essential functions like array_map, array_filter, array_reduce, and array manipulation.
07 — Mastering String Manipulation
Format, search, and transform text efficiently. Learn string concatenation, interpolation, escaping, searching and replacing, substring extraction, string formatting, case conversion, and working with multibyte strings for international applications.
Part 3: Object-Oriented Programming (Chapters 08–10)
Learn modern OOP principles that power professional PHP applications.
08 — Introduction to Object-Oriented Programming
Classes, objects, properties, methods, and encapsulation. Learn how to define classes, create objects, use constructors and destructors, understand visibility (public/private/protected), implement static methods and properties, and leverage PHP 8.4's property hooks and asymmetric visibility.
09 — OOP: Inheritance, Abstract Classes, and Interfaces
Build flexible, extensible class hierarchies. Understand inheritance and method overriding, abstract classes for partial implementations, interfaces for contracts, polymorphism for flexible code, type hinting with interfaces, and when to use each approach.
10 — OOP: Traits and Namespaces
Code reuse with traits and organize with namespaces. Learn how traits enable horizontal code reuse, resolve trait conflicts, use namespaces to organize code and prevent naming collisions, import classes with use statements, and follow PSR-4 autoloading standards.
Part 4: Professional PHP Development (Chapters 11–16)
Essential skills for production applications: error handling, dependencies, files, databases, and standards.
11 — Error and Exception Handling
Handle failures gracefully and debug effectively. Learn the difference between errors and exceptions, how to throw and catch exceptions, create custom exception classes, implement try-catch-finally blocks, and build robust error handling for production applications.
12 — Dependency Management with Composer
Use Composer to manage packages and autoloading. Master installing third-party packages from Packagist, managing dependencies with composer.json, autoloading classes with PSR-4, semantic versioning, and keeping dependencies up to date.
13 — Working with the Filesystem
Read, write, and manage files and directories safely. Learn to read and write files, check file existence and permissions, work with directories, handle file uploads securely, use file locking for concurrent access, and implement proper error handling.
14 — Interacting with Databases using PDO
Connect to databases and run secure queries with prepared statements. Master PDO for database abstraction, execute queries safely with prepared statements to prevent SQL injection, handle transactions, fetch results in various formats, and implement error handling.
15 — Managing State with Sessions and Cookies
Track users across requests and build authentication. Understand HTTP's stateless nature, use sessions to maintain user state across page requests, work with cookies for persistent data, implement user authentication and authorization, and secure session data.
16 — Writing Better Code with PSR-1 and PSR-12
Follow industry coding standards for readable, maintainable code. Learn PSR-1 basic coding standards, PSR-12 extended coding style guide, naming conventions, file structure best practices, and how to use PHP_CodeSniffer to enforce standards automatically.
Part 5: Building Real Applications (Chapters 17–19)
Put it all together: build a router, structure an app, and create a complete blog.
17 — Building a Basic HTTP Router
Create your own router to handle URLs and requests. Learn how routers work by building one from scratch. Understand URL parsing, route matching, HTTP methods (GET, POST, PUT, DELETE), route parameters, middleware concepts, and request/response handling.
18 — Project: Structuring a Simple Application
Design a clean MVC architecture from scratch. Learn how to organize a real application with Models (business logic and data), Views (presentation), Controllers (request handling), proper directory structure, configuration management, and separation of concerns.
19 — Project: Building a Simple Blog
Build a full CRUD application with authentication and database. Bring everything together in a complete blog application: user registration and login, creating/editing/deleting posts, comment system, file uploads, security best practices, and deployment preparation.
Part 6: Frameworks & Beyond (Chapters 20–23)
Graduate to modern frameworks and master essential web technologies.
20 — A Gentle Introduction to Laravel
Get started with the world's most popular PHP framework. Install Laravel, understand its elegant syntax, explore Artisan commands, work with Eloquent ORM, create routes and controllers, and see how Laravel simplifies everything you've learned.
21 — A Gentle Introduction to Symfony
Explore Symfony's powerful component architecture. Install Symfony, understand its bundle system, work with Doctrine ORM, create routes and controllers, use Twig templates, and discover how Symfony's flexibility supports enterprise applications.
22 — What to Learn Next
Continue your PHP journey with advanced topics and resources. Explore testing with PHPUnit, caching strategies, queues and async processing, package development, API development, security best practices, performance optimization, and career paths in PHP development.
23 — Working with JSON and APIs
Master JSON handling and consume RESTful APIs. Learn to encode and decode JSON, make HTTP requests with cURL, consume third-party APIs, handle API authentication, build your own RESTful API endpoints, and implement proper error handling and rate limiting.
Frequently Asked Questions
I've never programmed before. Can I really do this?
Absolutely! This series assumes zero programming knowledge. We start from "What is PHP?" and build up systematically. Thousands of developers have learned PHP as their first language.
How do I know when I'm ready to move to the next chapter?
Each chapter ends with exercises. If you can complete them without looking at the answers, you're ready to continue. Don't rush—mastery takes time.
Should I memorize all the functions?
No! Professional developers look things up constantly. Focus on understanding concepts, not memorizing syntax. The PHP documentation is excellent—learn to use it.
What if the exercises are too hard?
Go back and re-read the chapter. Try the example code yourself. Break the problem into smaller pieces. If you're still stuck, check the troubleshooting section or ask for help (see below).
Can I use PHP 8.0, 8.1, 8.2, or 8.3 instead of 8.4? Most examples will work on PHP 8.0+, but some advanced features (property hooks and asymmetric visibility in Chapter 8) specifically require PHP 8.4. We strongly recommend installing 8.4 to get the complete learning experience and avoid compatibility issues.
Which IDE/editor should I use?
Use whatever you're comfortable with. VS Code (free) is popular and has excellent PHP extensions. PhpStorm (paid, with free student licenses) is the industry standard. Even a simple text editor like Sublime Text works fine.
How long should each chapter take?
Most chapters take 30 minutes to 2 hours depending on your pace and how much you experiment. The project chapters (18–19) will take 3–5 hours each. Don't rush—understanding is more important than speed.
What comes after this series?
After completing this series, you'll be ready for framework-specific learning. We recommend either Laravel (most popular, great for startups and general web apps) or Symfony (powerful, used in enterprises). Both are covered in Chapters 20–21.
Getting Help
Stuck on something? Here's where to get help:
- Read the troubleshooting section in each chapter for common issues
- Check the code samples in
docs/series/php-basics/code/for working examples - Consult PHP documentation: php.net is comprehensive and well-maintained
- GitHub Discussions: Ask questions and share progress
- Report bugs: Open an issue for unclear explanations or broken examples
Related Resources
Want to dive deeper? These resources complement the series:
- PHP Manual: Official documentation (bookmark this!)
- PHP: The Right Way: Modern best practices and patterns
- PHP Fig (PSR Standards): Learn about community standards
- Composer: Dependency management (covered in Chapter 12)
- Laravel Documentation: After finishing the series
- Symfony Documentation: After finishing the series
Ready to Start?
Head to Chapter 00: Setting Up Your Development Environment to begin your journey!
Continue Your Learning
Finished this series? Take your skills further:
→ AI/ML for PHP Developers — Add intelligent features to your PHP applications
→ Python to Laravel — Explore Laravel if you know Python