There is no shortage of websites that use the PHP programming language in some or other capacity. PHP (Hypertext Preprocessor) is a server-side scripting language that allows you to create dynamically-generated web pages. Rasmus Lerdorf created PHP in 1994.
PHP works in the backend of a website because it is a server-side technology. This is the part of a website that no one sees. This means that PHP is frequently used to run server-side programs such as data collection and processing and database management. The fact that PHP is a simple language is one of the key reasons why learning it is a wise investment. PHP was created with the goal of speeding up web development; therefore, it features a basic syntax that is ideal for beginners. Furthermore, because PHP is a dynamically typed language, there are less restrictions to follow while creating features. The PHP programming language offers a wide range of applications and features, such as authentication, payments, user administration, and other "dynamic" aspects of a website.
Efficiency, syntax compatibility, platform independence, error detection, and encryption are just a few of the interesting properties of PHP.
Why Should You Learn PHP?
PHP developers work with the PHP programming language to create websites, applications, and programs. As a PHP developer, you’ll usually be working in IT companies (all over the world), but there are also a lot of opportunities in design and business. A PHP developer, like any other programming/scripting language developer, should be able to work with many languages and ideally have some knowledge of database, web design, or some page formatting language.
This Book Offers
• A step-by-step approach to problem solving and skill development
• A quick run-through of the basic concepts, in the form of a "Crash Course"
• Advanced, hands-on core concepts, with a focus on real-world problems
• Industry-level coding paradigms and a practice-oriented explanatory approach
• Special emphasis on writing clean and optimized code, with additional chapters focused on coding methodology
Author(s): Sufyan bin Uzayr
Publisher: CRC Press
Year: 2022
Language: English
Pages: 404
City: Boca Raton
Cover
Half Title
Title Page
Copyright Page
Contents
Acknowledgments
About the Author
CHAPTER 1: Introduction to PHP
HISTORY
WHY DO WE LEARN PHP?
VERSIONS OF PHP
PHP
What Is PHP?
What Can We Do with PHP?
Main Components
Pros and Cons of PHP
Built-in Templating Engine
PHP from the Command Line
Upgrading PHP in macOS
Upgrading PHP in Windows
Upgrading PHP in Ubuntu
Why Is PHP Still So Widely Used?
PHP Prerequisites
INSTALLATION OF PHP
How to Install PHP on Windows
How to Install PHP on Linux
Installing PHP on Ubuntu
How to Install PHP on macOS
Installing a Text Editor
Starting Apache to Run PHP Scripts
Place Your Project in the Root Directory of XAMPP
Printing Hello PHP on the Web Browser with a PHP File
PHP Hello World on the Command Line
PHP BASICS
Naming Conventions for PHP Variables
Echo Statement
Displaying Strings with the Print Statement
WHAT IS HTML (HYPERTEXT MARKUP LANGUAGE BASICS)?
Most Used HTML Tags and HTML Elements
Block-Level Elements
Inline Elements
Using PHP and HTML on a Single Page
CSS (CASCADING STYLE SHEETS)
What Is CSS?
CSS Syntax
Using CSS with PHP
Data Types
CHAPTER 2: Data Types and Operators
CODING BUILDING BLOCKS
VARIABLES
Reading a Variable’s Value
Types of Variables
PREDEFINED VARIABLES
IS PHP A CASE-SENSITIVE LANGUAGE?
REGULAR EXPRESSION
Why Does Perl Style Regular Expressions?
Regular Expression Syntax
Character Classes in Regular Expression
Built-in Regular Expression Functions in PHP
Regular Expression Metacharacters
DATA TYPES
What Is a Data Type?
Integers
Strings
WHAT IS PHP’S STRING FUNCTION?
String Functions
ESCAPE SEQUENCES
FLOATING POINT NUMBERS OR DOUBLES
Booleans
Arrays
Operator Keywords
Objects
NULL
Resources
Typecasting
Automatic Type Conversion
IMPLICIT AND EXPLICIT CASTING
EXPRESSIONS
Expressions with ++ and −− Operators
Expressions with Ternary Conditional Operator
OPERATORS
CHAPTER SUMMARY
CHAPTER 3: Control Statements
INTRODUCTION TO CONTROL STATEMENTS
LIST OF KEYWORDS AVAILABLE IN PHP
What Is a Keyword?
Operands Lvalue and Rvalue
Lvalue
Rvalue
LIST OF CONTROL STATEMENTS
The if Statement
The else Statement
else-if Statement
switch Statement
The ? Operator
Expressions with the Ternary Conditional Operator
Alternative Syntax for Control Structures (if, else-if)
while Loop
do-while Loop
for Loop
Breaking Out of the Loop
foreach
Continue
Break and Continue in while Loops
match
declare
return Statement
require Statement
include Statement
require_once Statement
include_once Statement
goto Operator
WHAT IS THE BOOLEAN EXPRESSION IN PHP?
Boolean Constant
CHAPTER SUMMARY
CHAPTER 4: PHP Functions
FUNCTIONS
DECLARING A FUNCTION
function return Statement
function with Default Argument Value
The function within Another function
The return Statement
Scope and the Global Statement
Working with print_r()
How to Pass PHP Variables by Reference
Pass by Reference
VARIABLE-LENGTH ARGUMENT FUNCTION
Built-in Functions in PHP
Recursion
Dynamic Function Calls
Callable
TYPES OF FUNCTIONS
Language Constructs
Function Handling Functions
Flag Parameters
INTRODUCTION TO PHP USER DEFINED FUNCTIONS
Namespace PHP Functions
PHP KEYWORDS AND IDENTIFIERS TUTORIAL
What Is an Identifier?
Rules for Naming Identifiers
Identifier Casing Conventions
TYPE HINTS
How to Use Array-Type Hinting
How to Use Object-Type Hinting
Does PHP Support Any Type Hinting for Some Basic Data Types?
THE SPLAT OPERATOR IN PHP
SIGNATURE
“PARAMETER” VS. “ARGUMENT”
Variable Functions
Anonymous Functions (Lambda)
Assigning the Anonymous Function to Variables
Using an Anonymous Function as the Callback
Why Do We Use Functions in a PHP Script?
HTML Code inside the Function in PHP
CHAPTER SUMMARY
CHAPTER 5: Object-Oriented Programming (OOP)
INTRODUCTION TO OOP
OOP THEORY
DEFINING A CLASS
NEW KEYWORD
WHAT ARE CONSTANTS?
Defining Constants
CREATING AN OBJECT
THE $this ATTRIBUTE
CREATING CONSTRUCTORS
CREATING DESTRUCTORS
PHP VARIABLE SCOPE
What Is Variable Scope?
Superglobals Explained
Static Variables
INTERFACE
PHP Abstract Class
INHERITANCE
ACCESS SPECIFIERS IN PHP
DATA ABSTRACTION
ABSTRACT METHODS AND CLASSES
ABSTRACT CLASSES COMPARED TO INTERFACES
ABSTRACT CLASSES IMPLEMENTING INTERFACES
CLASS MEMBERS
Abstract Method
Output
The Abstract Method with Arguments
PHP Magic Methods
IMPLEMENTATION OF POLYMORPHISM IN PHP
POLYMORPHISM IN PHP TO IMPLEMENT IN INTERFACES
POLYMORPHISM IMPLEMENTATION IN ABSTRACT CLASSES
OVERLOADING IN PHP
Types of Overloading
Static Methods and Properties
self vs. $this Keyword
WHAT IS SELF KEYWORD?
METHOD OVERLOADING IN PHP
How Does Method Overloading Work?
What Is Autoloading?
What Is an Autoloader?
NAMESPACES
ENCAPSULATION IN PHP
CHAPTER SUMMARY
CHAPTER 6: Using HTTP in PHP
WHAT DOES WEB MEAN?
WHAT IS HTTP AND WHAT IS THE STRUCTURE OF HTTP REQUEST AND RESPONSE?
WHAT IS HTTP?
How Do Web Servers Work?
Some Examples of Web Server Use
WHAT ARE STATIC WEB PAGES?
WHAT ARE DYNAMIC WEB PAGES?
HYPERTEXT TRANSFER PROTOCOL (HTTP)
UNIFORM RESOURCE LOCATOR
TERMINOLOGY
OVERALL OPERATION OF HTTP
UNIFORM RESOURCE IDENTIFIERS (URIs)
HTTP GENERAL SYNTAX
HTTP URL
HTTP REQUEST METHODS
GET REQUEST METHOD
RESPONSE STATUS CODE
HTTP HEADERS
Cache-Control
GENERAL HEADERS
Connection
Date
Pragma
Trailer
Transfer-Encoding
Upgrade
Via
Warning
CLIENT REQUEST HEADERS
Accept
Accept-Charset
Accept-Encoding
Accept-Language
Authorization
Cookie
Expect
From
Host
Proxy-Authorization
Range
SERVER RESPONSE HEADERS
Accept-Ranges
Location
Proxy-Authenticate
HTTP
How Does HTTPS Work?
What Does HTTPS Do?
What Information Does HTTPS Protect?
CHAPTER SUMMARY
CHAPTER 7: Data Persistence
WEB SERVER
File Read
File Write
File Close
feof() Function
fflush() Function
PHP fgetc() Function
fgets() Function
fgetcsv() Function
fgetss() Function
file_exists() Function
file_put_contents() Function
fileatime() Function
filectime() Function
filegroup() Function
filesize() Function
fileinode() Function
filemtime() Function
fileowner() Function
fileperms() Function
fpassthru() Function
fputcsv() Function
move_uploaded_file() Function
popen() Function
readfile() Function
readlink() Function
realpath() Function
clearstatcache() Function
basename() Function
copy() Function
dirname() Function
rename() Function
is_writable() Function
is_dir() Function
is_executable Function
is_file() Function
is_link() Function
is_readable() Function
is_uploaded_file() Function
is_writable() Function
chgrp( ) Function
chmod( ) Function
chown( ) Function
DATABASES
GUI CLIENTS
MySQL GUI Clients and Tools
MySQL Workbench
dbForge Studio
PHPMyAdmin
HeidiSQL
Toad Edge
MySQL
Types of Database Management Systems
RDBMS Terminology
MySQL Database (RDBMS)
MySQL CONNECTION USING PHP SCRIPT
CREATE A DATABASE USING PHP SCRIPT
MySQL INSERT
FETCHING DATA
UPDATING DATA
DELETING DATA
What Is SQL Injection in PHP?
The Basis of an SQL Injection Attack
Which Function Can Be Used to Avoid SQL Injection?
PREPARED STATEMENTS AND BOUND PARAMETERS
CHAPTER SUMMARY
CHAPTER 8: Error Handling in PHP
ERROR HANDLING
BASIC ERROR HANDLING
Use of the die() Function
CUSTOM ERROR HANDLER
UNDERSTANDING ERROR LEVELS
ERROR REPORT LEVELS
SET ERROR HANDLER
Way to Trigger an Error
LOGGING ERROR
Four Different Types of Errors in PHP
Introduction
PHP ERROR
Runtime Configuration
PHP ERROR AND LOGGING FUNCTIONS
debug_backtrace() Function
debug_print_backtrace() Function
error_get_last() Function
error_log() Function
error_reporting() Function
restore_error_handler() Function
restore_exception_handler() Function
set_error_handler() Function
set_exception_handler() Function
trigger_error() Function
user_error() Function
Error Handling
Using the die() Function
EXCEPTION HANDLING IN PHP
WHAT IS AN EXCEPTION?
THE EXCEPTION OBJECT
WHY DO WE NEED EXCEPTION HANDLING?
PHP Try-Catch with Multiple Exception Types
When to Use Try-Catch-Finally
CREATING CUSTOM PHP EXCEPTION TYPES
GLOBAL PHP EXCEPTION HANDLING
WHAT HAPPENS WHEN AN EXCEPTION IS TRIGGERED?
WHY HANDLE AN EXCEPTION?
PHP ERROR HANDLING
PHP Offers Several Methods to Handle Errors
Die Statement
How to Use Try-Catch with MySQL
PDO
PHP ERROR REPORTING
CHAPTER SUMMARY
CHAPTER 9: Working with Composer
WHAT IS A DEPENDENCY MANAGER?
WHAT IS PHP COMPOSER?
Dependency Management
DOWNLOADING THE COMPOSER EXECUTABLE
PHP Composer Installation on the Windows Operating System
System Requirements
Locally
Globally
PHP Composer Installation on Linux/Unix/macOS
Package Installation Using Composer
USING THE INSTALLER
Manual Installation
INSTALL PHP COMPOSER ON LINUX UBUNTU
PHP COMPOSER
INSTALL COMPOSER ON macOS
UPGRADE PHP COMPOSER
Understanding the Required Key
Package Names
Package Version Constraints
How Do We Update the Composer Itself?
Installing Dependencies
Committing Composer.lock File to Version Control
Installing from the Composer.lock File
Updating Dependencies to Their Latest Versions
WHAT IS PACKAGIST?
Platform Packages
AUTOLOADING
Why Do We Need Autoloading?
How Autoloading Works without Composer
How Autoloading Works with Composer
Autoloading: The Files Directive
Autoloading: The class-map Directive
Autoloading: PSR-0
LIBRARIES
Library Versioning
VCS VERSIONING
Lock File
Publishing to a VCS
Command-Line Interface
GLOBAL OPTIONS
CREATE A PROJECT USING THE COMPOSER
dump-autoload (dumpautoload)
BENEFITS OF USING COMPOSER
CHAPTER SUMMARY
CHAPTER 10: WEB Services
WHAT IS WEB SERVICE?
DIFFERENT TYPES OF WEB SERVICES
UDDI
SOAP
REST
COMPONENTS OF WEB SERVICES
HOW DOES A WEB SERVICE WORK?
API VS. WEB SERVICES
WHY DO YOU NEED A WEB SERVICE?
SIMPLE OBJECT ACCESS PROTOCOL (SOAP) 1.1
Characteristics of SOAP
Design Goals
The SOAP Message Exchange Model
SOAP Building Block
SOAP Structure
Examples of SOAP Messages
Relation to XML
SOAP Envelope
SOAP Header
SOAP Body
Relationship between SOAP Header and SOAP Body
SOAP Fault Codes
mustUnderstand
Client
Server
WEB SERVICES DESCRIPTION LANGUAGE (WSDL)
What Is WSDL PHP?
Features of WSDL
Is WSDL a Web Service?
The WSDL Document Structure
How Do I Find the WSDL for a Web Service?
How to Know if I Have a PHP SOAP Extension?
REST
What Is REST Architecture?
HTTP Methods
Introduction to RESTful Web Services
Advantages of RESTful Web Services
CHAPTER SUMMARY
CHAPTER 11: Using PHP-based CMSs
WHAT IS A CMS?
TYPES OF CMS
FEATURES OF CMS
WHAT ROLE DOES A CMS PLAY IN A BUSINESS?
THE DISADVANTAGES OF CMS
VARIOUS CMS
WordPress
What Are WordPress Hooks?
Purpose of Hooks
How to Use WordPress Hooks
Creating an Action Hook
Joomla
History
What Is Joomla in PHP?
Magento 2
History
What Is e-commerce?
Why Use Magento 2?
Installation
Drupal
History
Download Drupal
CHAPTER SUMMARY
APPRAISAL
BIBLIOGRAPHY
INDEX