MODULE CODE AND TITLE: SWDPP401 PHP PROGRAMMING
LEARNING OUTCOME1: Apply PHP Fundamentals.
Indicative content1: Preparation of PHP Programming environment
1. Definition of key terms
2. Php development tools
3. Configuration of environment
Indicative content2: Application of php concepts
Indicative content3: Application of PHP Security concepts
Indicative content4: Implementation of Object-oriented programming (OOP) in PHP
Learning outcome 2: Connect PHP to the Database
Indicative content1: Application of Database Connection drives
Indicative content2: Perform database CRUD Operations
Indicative content3: Application of PHP Basic security concepts
Indicative content4: Errors and exceptions in PHP
Indicative content5: Implementation of user authentication
Learning outcome 3: Build a Content Management System (CMS) using PHP
Preparation of Content Management System (CMS)
Build dynamic content navigation
Management of cookies and sessions
Application of Context and Options
Regulate page access
CMS Errors Detection
Maintain CMS
Learning outcome 4: Build a web app using MVC Framework (LARAVEL)
Framework environment configuration
Setup Laravel custom routing
Perform form data validation
Perform CRUD Operations
Manage APIs In Laravel frameworks
Authentication and Security
API Versioning and Documentation
1
Learning outcome 1: Apply PHP Fundamentals.
Indicative content1: Preparation of PHP Programming environment.
1. Definition of key terms
PHP stands for Hypertext Preprocessor. It is a general-purpose scripting language that
is especially suited to web development. PHP code is embedded in HTML pages and is
executed on the server side, meaning that the results of the PHP code are sent to the
browser as plain HTML.
PHP is a very popular language for web development, and it is used by many popular
websites and web applications, including Facebook, Wikipedia, and WordPress. It is
also a relatively easy language to learn, making it a good choice for beginners.
2. Interpreter
An interpreter is a computer program that transforms or interprets
(translates) a high-level programming code into code that can be
understood by the machine (machine code) or into an intermediate
language that can be easily executed as well.
3. Open source
Open source is a term that describes products, such as software, that are distributed
with the source code so that anyone can inspect, modify, and enhance it. The source
code is the part of software that most computer users don't ever see; it's the code
computer programmers can manipulate to change how a piece of software—a
"program" or "application"—works.
4. Web server
A web server is a computer that runs websites. It's a computer program that distributes
web pages as they are requisitioned. The basic objective of the web server is to store,
process and deliver web pages to the users.
5. Apache
Apache is a free and open-source web server software that allows users to deploy their
websites on the internet or locally.
6. Database
2
A database is an organized collection of structured information, or data, typically
stored electronically in a computer system.
7. DBMS
8. MySQL
MySQL is an open-source relational database management system (RDBMS). It is one
of the most popular database systems in the world, and it is used by many popular
websites and web applications, including Facebook, Wikipedia, and WordPress.
9. STATIC &DYNAMIC WEBSITES
In the context of website creation, static and dynamic refers to the ways in which
websites deliver and display content. The key difference between static websites vs
dynamic websites is that static websites have stable content, where every user sees the
exact same thing on each individual page (like a privacy policy), whereas dynamic
websites pull content on-the-fly, allowing its content to change with the user.
3
Indicative content 1.4: Implementation of Object-oriented programming (OOP) in
PHP.
Object-Oriented Programming (OOP) is a programming paradigm centered around the
concept of "objects." Objects are instances of classes, which can be thought of as
blueprints for creating individual instances. OOP allows for the organization of software
design around data, or objects, rather than functions and logic.
Key concepts in OOP include:
1. Classes and Objects
2. Encapsulation
3. Inheritance
4. Polymorphism
5. Abstraction
Topic 1: Classes and Objects
Class: A class in PHP is a blueprint for creating objects. It defines properties (attributes)
and methods (functions) that the objects created from the class will have.
Object: An object is an instance of a class. It is a specific implementation of the class
with actual values.
Example:
<?php
class Dog {
public $name;
public $age;
public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
public function bark() {
return $this->name . " says woof!";
4
}
$myDog = new Dog("Buddy", 3);
echo $myDog->name; // Output: Buddy
echo $myDog->bark(); // Output: Buddy says woof!
?>
Topic 2. Encapsulation
Encapsulation involves wrapping data and methods that operate on the data into a single unit or class
and restricting direct access to some of the object's components.
Example:
<?php
class BankAccount {
private $balance;
public function __construct($balance) {
$this->balance = $balance;
public function deposit($amount) {
if ($amount > 0) {
$this->balance += $amount;
public function withdraw($amount) {
if ($amount <= $this->balance) {
$this->balance -= $amount;
5
}
public function getBalance() {
return $this->balance;
$account = new BankAccount(1000);
$account->deposit(500);
echo $account->getBalance(); // Output: 1500
?>
Topic 3. Inheritance
Inheritance allows a class to inherit properties and methods from another class. The new class (child
class) inherits attributes and methods from the existing class (parent class).
Example:
<?php
class Animal {
public $name;
public function __construct($name) {
$this->name = $name;
public function makeSound() {
return $this->name . " makes a sound";
6
}
class Cat extends Animal {
public function makeSound() {
return $this->name . " says meow";
$genericAnimal = new Animal("Generic");
$cat = new Cat("Whiskers");
echo $genericAnimal->makeSound(); // Output: Generic makes a sound
echo $cat->makeSound(); // Output: Whiskers says meow
?>
4. Polymorphism
Polymorphism allows methods to do different things based on the object it is acting upon, even if they
share the same name.
Example:
<?php
class Bird {
public function speak() {
return "Bird sound";
class Parrot extends Bird {
public function speak() {
return "Parrot says hello!";
7
}
class Penguin extends Bird {
public function speak() {
return "Penguin says squawk!";
$parrot = new Parrot();
$penguin = new Penguin();
$birds = [$parrot, $penguin];
foreach ($birds as $bird) {
echo $bird->speak() . "\n";
// Output:
// Parrot says hello!
// Penguin says squawk!
?>
5. Abstraction
Abstraction hides the complex implementation details and shows only the essential features of the
object. It can be achieved through abstract classes and interfaces.
Example:
<?php
abstract class Shape {
abstract public function area();
8
class Rectangle extends Shape {
private $width;
private $height;
public function __construct($width, $height) {
$this->width = $width;
$this->height = $height;
public function area() {
return $this->width * $this->height;
class Circle extends Shape {
private $radius;
public function __construct($radius) {
$this->radius = $radius;
public function area() {
return 3.14 * $this->radius * $this->radius;
$rectangle = new Rectangle(3, 4);
$circle = new Circle(5);
9
echo $rectangle->area(); // Output: 12
echo $circle->area(); // Output: 78.5
?>
10