Module 1.1 Lesson
Module 1.1 Lesson
In modern PHP development, OOP is often preferred due to its ability to handle large and complex
applications effectively. However, procedural programming is still valuable for simpler tasks and learning
foundational programming concepts.
LESSON 1.1
PHP (Hypertext Preprocessor) is a widely-used open-source scripting language primarily designed for
web development. It can be embedded into HTML and is often used to create dynamic web pages and
applications. PHP is known for its ease of use and flexibility, and it is supported by many web servers and
databases.
• Origins: PHP was created by Danish-Canadian programmer Rasmus Lerdorf in 1993. Originally, it
was a set of Common Gateway Interface (CGI) scripts called "Personal Home Page Tools" for
tracking visitors to his online resume.
• Evolution: It evolved significantly over the years. By 1995, it was released as PHP/FI (Personal
Home Page Forms Interpreter). The language continued to develop, with major versions released
over time, including PHP 4 (2000) and PHP 5 (2004), each bringing substantial improvements.
PHP 7 (2015) and PHP 8 (2020) introduced even more enhancements, such as performance
improvements and new features.
Core Features
• Server-Side Scripting: PHP is executed on the server, which means the server processes the PHP
code and sends the resulting HTML to the client's web browser.
• Embedded HTML: PHP code can be embedded within HTML code, making it easy to generate
dynamic web pages. It uses <?php and ?> tags to distinguish PHP code from HTML.
• Database Integration: PHP is known for its strong integration with databases, particularly
MySQL, but it supports other databases as well like PostgreSQL and SQLite.
• Open Source: PHP is open source, which means its source code is freely available for anyone to
use, modify, and distribute. This has contributed to its widespread
Common Uses
• Dynamic Web Pages: PHP is used to create dynamic and interactive web pages. For example, it
can handle form submissions, manage sessions, and generate content based on user
interactions.
• Content Management Systems (CMS): Many popular CMS platforms like WordPress, Joomla,
and Drupal are built with PHP.
• Web Frameworks: PHP has a variety of frameworks that simplify and streamline web
development, such as Laravel, Symfony, and CodeIgniter.
LESSON 1.2
Procedural Programming and Object-Oriented Programming (OOP) are two different paradigms for
structuring PHP code. Each has its own strengths and use cases.
Procedural Programming
Procedural Programming is a paradigm based on the concept of procedure calls. It organizes code into
procedures or functions that operate on data. In PHP, procedural programming is straightforward and
involves writing functions and scripts that execute sequentially.
Characteristics:
• Linear Code Execution: Code is executed top-down, following a sequence of function calls.
• Global State: Data is often stored in global variables, which can be accessed and modified by
various functions.
• Function-Based: Code is organized into reusable functions, but there’s no inherent structure for
managing data and functions together.
Example:
<?php
$width = 10;
$height = 20;
?>
Advantages:
• Less Overhead: Fewer abstractions compared to OOP, which can be less resource-intensive.
Disadvantages:
• Scalability Issues: As codebases grow, managing and maintaining procedural code can become
challenging.
• Code Duplication: Lack of inherent structure can lead to repeated code and higher chances of
errors.
Object-Oriented Programming organizes code into classes and objects, promoting a more modular and
reusable approach. OOP focuses on modeling real-world entities and their interactions.
Characteristics:
• Classes and Objects: Code is structured into classes that define properties and methods. Objects
are instances of classes.
• Encapsulation: Data and methods are bundled together, with controlled access through public
methods.
• Inheritance: Classes can inherit properties and methods from other classes, promoting code
reuse.
• Polymorphism: Allows objects of different classes to be treated as instances of the same class
through a common interface.
Example:
<?php
// Define a class
class Rectangle {
private $width;
private $height;
$this->width = $width;
$this->height = $height;
}
public function getArea() {
?>
Advantages:
• Modularity: Code is organized into classes, making it easier to manage and extend.
• Reusability: Inheritance and traits allow code to be reused across different parts of an
application.
• Maintainability: Encapsulation and abstraction make it easier to maintain and update code.
Disadvantages:
• Complexity: OOP introduces additional abstractions, which can make learning and
implementation more complex for beginners.
• Overhead: May involve more overhead compared to procedural code, especially in terms of
memory and performance.
Summary
• Procedural Programming: Best for simple, linear tasks and scripts. It is straightforward but can
become cumbersome as the complexity of the project increases.
• Object-Oriented Programming (OOP): Provides a more robust framework for building complex
and scalable applications. It promotes code reuse, modularity, and maintainability but comes
with additional complexity.