0% found this document useful (0 votes)
3 views

Module 1.1 Lesson

This document introduces PHP, a widely-used open-source scripting language for web development, highlighting its history, core features, and common uses. It compares procedural programming and object-oriented programming (OOP) in PHP, outlining their characteristics, advantages, and disadvantages. Procedural programming is simpler and suitable for small tasks, while OOP offers modularity and reusability for complex applications but introduces additional complexity.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Module 1.1 Lesson

This document introduces PHP, a widely-used open-source scripting language for web development, highlighting its history, core features, and common uses. It compares procedural programming and object-oriented programming (OOP) in PHP, outlining their characteristics, advantages, and disadvantages. Procedural programming is simpler and suitable for small tasks, while OOP offers modularity and reusability for complex applications but introduces additional complexity.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

MODULE 1: INTRODUCTION TO PHP

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

Brief Overview of PHP

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.

History and Development

• 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.

• Cross-Platform: PHP is cross-platform, meaning it runs on various operating systems, including


Windows, Linux, and macOS.

• 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

Comparison of Procedural and OOP in PHP

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

// Function to calculate area

function calculateArea($width, $height) {

return $width * $height;

// Calculate and display area

$width = 10;

$height = 20;

echo "The area is: " . calculateArea($width, $height);

?>
Advantages:

• Simplicity: Easier to understand for small scripts or simple tasks.

• 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 (OOP)

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;

public function __construct($width, $height) {

$this->width = $width;

$this->height = $height;

}
public function getArea() {

return $this->width * $this->height;

// Create an object of the class

$rectangle = new Rectangle(10, 20);

// Calculate and display area

echo "The area is: " . $rectangle->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.

You might also like