Chapter 5 - PHP Fundamentals
Chapter 5 - PHP Fundamentals
Chapter 5 - PHP Fundamentals
PHP Fundamentals
CSE@ASTU 1
Outline
• Overview of PHP
• Fundamentals of programming in PHP
• Introduction to OOP in PHP
• On the lab session
How to start working with PHP
Installation: XAMP/WAMP, Editor
Writing first PHP program
CSE@ASTU 2
PHP overview
3
Why we learn PHP?
4
Overview ….
5
variables
6
Constants
• Used to define values that cant change while the script is running,
such as configuration settings
• defined using defin() function which accepts two arguments
– the name of the constant and its value
7
Data types
9
Conditional statements
10
PHP Array
11
Loops
2019 / 2011 EC 12
Functions
Reading assignment:
- callback functions, anonymous functions, arrow functions
13
Class and objects
14
Class
Abebe Hadra
15
class
• A class can be declared using the class keyword, followed by the name of
the class and a pair of curly braces ({})
• Once a class has been defined, objects can be created from the class with
the new keyword.
• Class methods and properties can directly be accessed through pseudo-
variable $this object instance.
• The arrow symbol (->) is an OOP construct that is used to access contained
properties and methods of a given object
2019 / 2011 EC 16
Defining a class, properties and methods
<?php
//Rectangle.php
class Rectangle
{
// Declare properties
public $length = 0;
public $width = 0;
18
<?php class Customer extends User {
var $city;
class User { var $state; // or province
var $country;
var $is_admin = false;
function location() {
return $this->city . ", " . $this->state . ", " . $this->country;
var $first_name;
}
var $last_name;
var $username; }
20
Visibility modifiers
21
Magic methods
22
Static ….
23
Static properties and methods
25
Inherited static ….
26
Static….
27
Class constants
28
Contants….
29
Setter and getter methods
30
Setter & getter..
31
Setter & getter…
32
33
Next session Topics
• Forms
• Session and cookies
• Files basics
• Database
CRUD
2019 / 2011 EC 34
Reading Assignment
• PHP strings
• Operators
• Late static binding
• Super global
• Autoloading
2019 / 2011 EC 35