Tutorials covering PHP 5 and 7

In Dec 2015, PHP 7 was released, bringing numerous improvements and new features, such as: New Zend Engine, improved performance, reduced memory usage, abstract syntax tree, improved exception hierarchy, many fatal errors converted to exceptions, secure random number generator, removed old and unsupported SAPIs and extensions, the null coalescing operator, return and Scalar type declarations, anonymous classes, and many others.

Introducing PHP

This tutorial covers: PHP basics such as: tags, comments, echo, print, echo shortcut and difference between echo and print and why to use PHP?

PHP Development Environment

Learn how to test PHP scripts on your laptop or computer by installing PHP, Apache and MySQL. You'll also learn how to write a PHP script using a code editor or IDE.

Variables and data types

Variables in PHP are identified by a dollar sign ($) followed by the variable name. Variables don't need to be declared, and they have no type until they are assigned a value.

String - Heredoc and Nowdoc

A string is any series of characters enclosed in single (‘) or double (“) quotes, or that you create using special heredoc or nowdoc syntax.


A constant is a variable with a value that cannot be changed by the script. Constants may not be redefined or undefined once they have been set. PHP provides two methods for creating constants: the const modifier and the define() function.

Variable Assignment, Operators and Expressions

In this tutorial we'll discuss the most fundamental parts of PHP programming language: variable assignment, expressions and operators.

Determine Variable Data Type

In PHP, you can initialize a variable with an integer value, add a float value to it, thereby turning it into a float, then join it onto a string value to produce a string.

Type Conversion

PHP provides several mechanisms to allow variables of one type to be considered as another type. Variables can be explicitly converted to another type with the settype, strval, intval, boolval and floatval functions.

Using namespaces in PHP

Namespaces help to avoid naming collisions between libraries and shared code. A namespace will encapsulate the codes (classes, functions and constants) inside it so that they don’t conflict if the same declared elsewhere.

Autoloading classes, interfaces or traits

Learn how to load classes files when they are required using PHP's autoloading feature.

Using Traits

A trait defines methods intended to be used by multiple classes. The structure of a trait is the same as a class, except that it’s declared using the keyword trait instead of class.

Using Generators and Yield

Any function containing yield is a generator function. A generator is used to generate a series of values which returned with yield statement.

Anonymous (Lambda) functions and Closures

A lambda function (also commonly referred to as an anonymous function) is a function that was declared without any named identifier to refer to it. A closure is a lambda which closes over the environment in which it was defined.

Type declaration and return type declaration

PHP 7 now offers the possibility to strict type variables and function signatures, known as “Type declarations” (“type hints” in PHP 5) and “Return type declarations”.

The ternary operator

The ternary operator can replace a single if/else clause. It uses three expressions, if the first one is evaluated to true, then the second expression is returned, otherwise the third one is returned.

Null coalescing operator ??

PHP 7 introduced “null coalesce operator (??)” to check whether a variable contains value , or returns a default value. This operator ?? is ideal to use with $_POST and $_GET for getting input from users or urls.

The goto operator

PHP 5.3.0 introduced the goto statement, which performs a jump to a specified label (line) within the same file.