PHP Basics

Maximiliano Firtman

Maximiliano Firtman

Independent Consultant
4 hours, 18 minutes CC
PHP Basics

Course Description

Learn the language powering over 70% of the web and navigate CMSs like WordPress with ease! Get a quick introduction to PHP basics, including syntax, variables, loops, and functions. Work with forms, build APIs, and connect to an SQLite database to craft dynamic, data-driven web applications!

This course and others like it are available as part of our Frontend Masters video subscription.

Preview
Close

Course Details

Published: August 19, 2024

Learning Paths

Learn Straight from the Experts Who Shape the Modern Web

Your Path to Senior Developer and Beyond
  • 200+ In-depth courses
  • 18 Learning Paths
  • Industry Leading Experts
  • Live Interactive Workshops
Get Unlimited Access Now

Table of Contents

Introduction

Section Duration: 25 minutes
  • Introduction
    Maximiliano Firtman begins the course by sharing his web development journey and discussing the topics covered. The prerequisites for the course include basic programming experience and familiarity with object-oriented programming concepts. Experience writing HTML will also be helpful.
  • Why PHP?
    Maximiliano explains that 76% of websites use PHP. While several websites use WordPress, the most popular content management system, companies like Meta, Microsoft, and Wikipedia still have PHP as part of their infrastructure. This presents a large opportunity for future PHP developers.
  • History of PHP
    Maximiliano shares a brief history of PHP, from its early beginnings in 1993 through the current version 8, which was released in 2020. This lesson also explains the PHP elephant mascot.

PHP Syntax

Section Duration: 1 hour, 11 minutes
  • PHP Language Features
    Maximiliano walks through some of the language features of PHP. Since PHP is an interpreted language, the source code is not compiled but shipped directly to the server.
  • Installation & Setup
    Maximiliano discusses the local and production requirements for PHP. Locally, a PHP interpreter is required. The interpreter can be installed individually or as part of a full LAMP stack, which includes Linux, Apache, MySQL, and PHP. In production environments, most shared hosting services support PHP or can be run in a cloud provider through a Docker image.
  • PHP Tags
    Maximiliano creates a simple PHP file and demonstrates PHP tags. These tags contain the executed PHP code. Anything outside a PHP tag is considered string output. The closing tag can be omitted when a file only contains PHP code, and static string output is not wanted.
  • Variables
    Maximiliano demonstrates how to create variables in PHP. Variables are prefixed with a dollar sign and are dynamically typed, meaning you can change the type assigned to the variable at any time. The concept of "variable variables" is introduced. They allow the name of a variable to be stored in a variable and a value assigned with a double dollar sign.
  • Strings
    Maximiliano highlights the difference between single, double, and multi-line use cases when creating String values in PHP. Strings can be concatenated with the ".", not the "+" like in other languages. Strings using double quotes support variable interpolation.
  • Arrays
    Maximiliano demonstrates how to create arrays in PHP. The array() constructor accepts the list of items to build the array. Square bracket notation is also supported. Keys can be provided to create an associative array like a dictionary or map. The global function count() will return the length of an array.
  • Loops
    Maximiliano demonstrates the while, do while, for, and foreach loops. Like other languages, curly braces contain the body of the loop. PHP has an alternative syntax to add a colon at the beginning of the loop and an identifier like endforeach to terminate the loop.
  • Functions
    Maximiliano introduces PHP functions. The function keyword is used in the declaration. Arguments are prefixed with a dollar sign like with variables and can have a type specified. This lesson also demonstrates the new named argument feature of PHP 8.

Building Web Applications with PHP

Section Duration: 33 minutes
  • Starting a PHP Development Server
    Maximiliano starts a development server from the terminal and specifies the host and port. The development server will serve static files like any other web server. PHP files are treated like HTML files, so any HTML content is rendered in the browser. Because of the ".php" extension, PHP code will be rendered on the server, and only the output will be returned to the browser.
  • Creating a Form
    Maximiliano begins the Cryptomasters example by creating an index.php file and coding a basic HTML form. The form will take a US dollar value as input and convert it to an equivalent cryptocurrency value.
  • Superglobal Variables & URL Parameters
    Maximiliano introduces superglobal variables that give you access to GET and POST data sent from a form. There are other superglobal variables for accessing cookies, session, and other server-related data. In this lesson, the GET superglobal variable accesses the amount and crypto variables in the URL.
  • Post Parameters
    Maximiliano demonstrates the difference between the GET and POST superglobal variables. POST data is sent from the form through the headers in the request rather than on the URL. The "issset" method is used to ensure the data is sent before it's used on the page.
  • phpinfo & Server Variables
    Maximiliano reviews a few additional superglobal variables. Server variables and the "phpinfo" function are also demonstrated and tips for debugging more complex data types like arrays are also shared.

Object Oriented Programming in PHP

Section Duration: 39 minutes

Creating an API Endpoint

Section Duration: 16 minutes

Databases, Testing & Debugging

Section Duration: 1 hour, 7 minutes

Wrapping Up

Section Duration: 4 minutes

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now