Matthew M.

Matthew M.

Introduction to Object-Oriented Programming

Slide Duration:

Table of Contents

Section 1: Advanced PHP with MySQL
Course Introduction

13m 36s

Intro
0:00
Advanced PHP w/ MySQL
0:13
Course Introduction
0:14
Course Content
0:59
Web Application: Educator Store
1:45
Web Application: Educator Store
1:46
Object-Oriented Programming
6:09
Object-Oriented Programming Overview
6:10
MySQL
6:50
MySQL Overview
6:51
Example: Command Prompt & MySQL
8:34
What You Will Learn
9:34
What You Will Learn
9:35
Course Prerequisites
11:52
Course Prerequisites
11:53
Advanced Course Development Environment

18m 46s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Development Environment Setup
1:36
Firefox Web Browser, XAMPP, and PSPad Text Editor
1:37
Course Directory Structure
4:36
Course Directory Structure
4:37
phpDocumentor
7:23
phpDocumentor Overview
7:24
Parsing Source Code
7:44
docs Subdirectory
9:06
Asvanced PHP Course Documentation Example
10:21
Previous Educator PHP Students
14:14
Lib Directory Changes
14:38
Images Directory Changes
14:57
VERSION Constant
15:40
Comments Noting a Specific Version Number
17:04
Homework Challenge
17:30
Homework Challenge
17:31
Introduction to File I/O

35m 37s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
File I/O
1:34
File I/O Overview
1:35
Performing file I/O: 3 Steps
1:52
File Permissions
2:28
Read Permission & Write Permission
2:29
fopen()
4:47
fopen()
4:48
Two Required Parameters
5:01
Successful fopen(): File Handle and Resource
5:21
FALSE and E_WARNING Error
6:00
Example
6:39
File Paths
7:10
File Paths
7:11
File Access Modes
9:18
File Access Modes
9:19
Coding Example: fopen()
10:31
Using Relative and Absolute Path & Non-Existent File
10:32
File Pointers
15:55
File Pointers
15:56
Example File
16:11
Opening a File with fopen() Using 'r' as the Access Mode
16:22
fgets()
17:55
fgets() Overview
17:56
Coding Example: fgets() - Reading a Line at a Time
18:26
feof()
20:10
feof() Overview
20:09
Coding Example: feof()
20:50
fclose()
23:43
fclose() Overview
23:44
Coding Example: fclose()
25:02
Coding Example: Current Stock
26:10
Coding Example: Current Stock
26:11
trim ()
31:39
trim () Overview and Example
31:40
Homework Challenge
33:35
Homework Challenge
33:36
Web Application Development

36m 36s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Version 1.0 Changelog
0:31
catalog.php
0:32
Function Library: fileLIB.php
5:00
Version 1.1 Changelog
27:12
createItemDataArray() and createDeptDataArray()
27:13
outputSimpleItemLink() and outputSimpleDeptLink()
32:06
HTTP & the POST Method

34m 36s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
HTTP Model
1:28
HTTP Model
1:29
Client-Server Model 2 Steps Process
2:00
HTTP Messages
2:23
HTTP Messages
2:24
HTTP Requests
3:09
HTTP Requests
3:10
Example: HTTP Request Header
3:17
Coding Example: HTTP Requests
4:29
HTTP Responses
7:15
HTTP Responses
7:16
Example: HTTP Response (Header & Body)
8:00
header()
11:47
header() Overview
11:48
Coding Example: header
14:02
Coding Example: header() Error
14:52
GET Method
18:55
GET Method
18:56
Coding Example: GET Method
20:13
POST Method
21:09
POST Method
21:10
Coding Example: Sample Form Using the POST Method
23:50
Accessing POST Data in PHP
26:38
Accessing POST Data in PHP
26:39
Coding Example: Accessing POST Data via $_POST
28:15
GET vs. POST
29:54
GET vs. POST
29:55
Example: Accessing POST Data via $_POST
31:20
Example: Accessing POST Data via $_POST
31:21
Homework Challenge
33:00
Homework Challenge
33:01
Web Application Development

14m 11s

Intro
0:00
Version 2.0 Changelog
0:09
Updating the Site's Current Form to Use the POST Method
0:10
Creating Admin Website
2:55
Dynamically Generated Department List
12:40
Writing to Files

17m 38s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Review of File I/O
0:40
Review of File I/O
0:41
fwrite()
1:38
fwrite()
1:39
fputs()
2:20
'r+'
2:31
Coding Example: fwrite()
2:59
fopen() Access Modes
8:41
'a' and 'a+'
8:42
'w' and 'w+'
11:34
Homework Challenge
14:47
Homework Challenge
14:48
Web Application Development

28m 14s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Updated Open File Functions
0:19
openItemsDataFile ( ), openDeptsDataFile ( ), and openLastAddedFile ( )
0:20
insertItem()
6:25
insertItem() Overview
6:26
Functions: createItemDataString ( ) and updateLastItemAdded ( )
7:07
addItemToDepartment ()
16:03
addItemToDepartment () Overview
16:04
Functions: createDeptDataString ( ) and updateDepartment ( )
17:55
HTTP POST: File Uploads

22m 51s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
POST Data Encoding
1:13
POST Data Encoding
1:14
When Data is Included in the Body of the HTTP POST Request and is of the Content Type
1:31
When Uploading Files Using HTTP POST
3:17
Uploading Files
6:22
Uploading Files
6:23
If Encoding Type is Not Set to Multipart/Formdata
9:27
$_FILES Superglobal
10:59
$_FILES Superglobal
11:00
Structure of $_FILES
12:15
Structure of $_FILES: Name, Type, tmp_name, Error, and Size
12:16
Coding Example: $_FILES Superglobal
13:34
Moving an Uploaded File
15:39
Introduction to Moving an Uploaded File
15:40
move_uploaded_file ( ): Definition and Example
16:40
Homework Challenge
21:19
Homework Challenge
21:20
Web Application Development

15m 30s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Uploading Item Image File
1:22
Uploading Item Image File
1:23
Uploading Item Image File (cont.)
2:43
Altering insertItem ( )
2:44
Helpfer Functions: getFileExtension ( ) and moveUploadedFile ( )
4:30
isValidItem ( )
13:03
Introduction to Object-Oriented Programming

32m 44s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Object-Oriented Programming
0:56
Introduction to Object-Oriented Programming
0:57
Associative Arrays
5:27
Associative Arrays
5:28
Classes
7:27
Classes Overview
7:28
Defining Classes
8:24
Defining Classes
8:25
Declaring Class Properties
9:25
Coding Example: Classes
10:11
Objects
12:18
Objects Overview
12:19
Classes vs. Objects
12:49
Classes vs. Objects
12:50
Instantiating Classes
14:58
Instantiating Classes
14:59
Coding Example: Instantiate an Item Object
16:30
Object Properties
19:21
Access and Set an Object's Property
19:22
Coding Example: Set & Access the Properties of an Item Object
24:23
Homework Challenge
30:22
Homework Challenge
30:23
Web Application Development

17m 47s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 5.0 Overview
0:50
Version 5.0 Overview and Examples
0:51
Outputting Object Properties
12:38
Outputting Object Properties
12:39
Array Object Properties
14:18
Access and Set Array Value
14:19
Object Methods

39m 57s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Object Methods
0:52
Definition of Object Methods
0:53
Calling Object Methods
3:25
Calling Object Methods
3:26
Coding Example: Simple Object Methods
4:44
Object Methods and Return Values
7:02
$this Variable
10:06
$this Variable: Definition and Example
10:07
$this Variable (cont.)
15:51
$this Variable (cont.)
15:52
Getters & Setters
21:21
Getters & Setters Methods
21:22
Object Methods In Strings
25:46
Object Methods In Strings
25:47
Coding Example: Outputting Method Return Values in Strings
27:41
Using $this to Call Other Methods
28:49
Using $this to Call Other Methods
28:50
Homework Challenge
34:18
Homework Challenge: 1-3
34:19
Homework Challenge (cont.)
36:20
Homework Challenge: 4-6
36:21
Homework Challenge (cont.)
37:52
Homework Challenge: 7-10
37:53
Web Application Development

17m 30s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 6.0 Overview
0:40
Version 6.0 Changes & Examples
0:41
Item Methods
0:53
Item Class Definition: getImageFilename()
0:54
Coding Example: getImageFilename()
1:58
Department Methods
7:33
addItem(), removeItem(), and isItemInDept() Method
7:34
addItemtToDepartment() & buildDeptObject() Functions
11:46
A Default Value Needed to Be Set for $items
16:26
Object Constructors

22m 20s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Object Constructors
0:32
Introduction to Object Constructors
0:33
Coding Example: Object Constructors
1:43
Defining Constructors
3:26
Defining Constructors
3:27
Coding Example: Constructors with No Arguments
4:24
Constructor Arguments
8:09
Constructor Arguments
8:10
Coding Example: Constructor Arguments
9:49
Important Notes
16:13
Important Notes
16:14
Homework Challenge
17:35
Homework Challenge: 1 - 4
17:36
Homework Challenge (cont.)
19:13
Homework Challenge: 5 - 9
19:14
Homework Challenge (cont.)
21:40
Homework Challenge: 10 and 11
21:41
Web Application Development

16m 19s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
Version 7.0 Overview
0:39
Version 7.0 Overview
0:40
Item Constructor
2:19
Item Constructor
2:20
Department Constructor
7:47
Department Constructor
7:48
Customer Constructor
12:23
Customer Constructor
12:24
More Magic Methods

53m 37s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
Magic Methods
1:12
Magic Methods
1:13
Destructors
2:45
Destructors Overview
2:46
Coding Example: Calling Destructors
4:30
Coding Example: Object Destructor
9:19
_to String ()
16:12
_to String () Overview
16:13
Coding Example: _to String () Magic Method
18:10
Access Modifiers
21:23
Introduction to Access Modifiers
21:24
Access Modifiers: Public
21:39
Access Modifiers: Private
22:18
Access Modifiers: Protected
22:41
Object Properties and Methods
23:06
Coding Example: Public Access Modifiers
26:48
Coding Example: Private Access Modifiers
28:30
_get()
31:37
_get() Overview
31:38
Coding Example: _get () Magic Method
33:30
_set ()
36:23
_set () & the Magic Method
36:24
Using Getters & Setters
44:37
Coding Example: Using Getters & Setters
44:38
Homework Challenge
50:33
Homework Challenge: 1 - 6
50:34
Homework Challenge (cont.)
51:41
Homework Challenge: 7 - 12
51:42
Web Application Development

31m 12s

Intro
0:00
Version 8.0 Review
0:12
Version 8.0 Review
0:13
private Object Properties
1:15
private Object Properties
1:16
Coding Example
2:54
_toString() Methods
6:51
_toString() Methods
6:52
Coding Example
8:09
DataFile Class
13:27
DataFile Class & I/O Operations
13:28
Using DataFile Class: Instantiate a DataFile, DataFile open () Method, and DataFile close () Method
18:09
Homework Challenge
29:35
Homework Challenge
29:36
Classes vs. Objects

37m 49s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
Class vs. Object Review
0:58
Class vs. Object Review
0:59
Static Properties
2:42
Static Properties
2:43
Scope Resolution Operator (::)
5:26
Scope Resolution Operator (::) & Static Property
5:27
Coding Example: Accessing a Static Property Using the Scope Resolution Operator
7:57
Coding Example: Accessing a Static Property in a Class Definition
10:33
Coding Example: Using a Static Property as an Instance Counter
14:18
Static Methods
18:51
Static Methods Overview
18:52
Coding Example: Static Methods
21:39
Classes vs. Objects
26:28
Classes vs. Objects: Diagrams
26:29
Class Constants
30:24
Class Constants Definition
30:25
Coding Example: Using Class Constants
31:55
Homework Challenge
34:01
Homework Challenge: 1 - 5
34:02
Homework Challenge (cont.)
35:25
Homework Challenge: 6 - 10
35:26
Web Application Development

21m 7s

Intro
0:00
Version 9.0 Overview
0:12
Version 9.0 Changes & Examples
0:13
Output Class
1:08
Output Class & Static Methods
1:09
outputHtmlSelector ( ) Method
2:43
outputItemSelector ( ) Method
4:53
outputDeptSelector ( ) Method
6:42
buildObject() Methods
11:54
buildObject() Methods & Examples
11:55
Exceptions

22m 43s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
try Blocks
0:44
try Blocks Definition
0:45
catch Blocks
2:03
catch Blocks: Definition and Syntax
2:04
Coding Example: try/catch Blocks
3:48
When an Exception Object is Caught & Error Handling
5:59
Exception Class
7:02
Exception Class
7:03
Coding Example: Using try/catch to Catch an Exception Thrown from a Method
8:04
Re-Throwing Exceptions
16:39
Re-Throwing Exceptions
16:40
Coding Example: Re-throwing an Exception
17:21
Homework Challenge
20:40
Homework Challenge: 1 - 5
20:41
Homework Challenge (cont.)
22:17
Homework Challenge: 6
22:18
Web Application Development

22m

Intro
0:00
Version 10.0 Overview
0:11
Updating addItem.php, addItemToDept.php, and error.php
0:12
Updating DataFile Class: open ( ) Method & try/catch blocks
7:45
Version 10.1 Overview
13:37
Version 10.1 Changes & Examples
13:38
Updating DataFile Class: close ( ) Method & logWarning ( )
20:17
Cookies

39m 47s

Intro
0:00
Lesson Overview
0:09
Lesson Overview
0:10
What is a Cookie?
1:15
Definition of Cookie
1:16
HTTP - A Stateless Protocol
2:17
HTTP - A Stateless Protocol
2:18
Purpose of Cookies
4:10
Set - Cookie Header
6:21
Introduction to Set - Cookie Header
6:22
Coding Example: Set - Cookie Header
7:38
Cookie Header
9:45
Introduction to Cookie Header
9:46
Example: Cookie Header
10:27
setcookie()
12:33
Introduction to setcookie()
12:34
Example: Using setcookie
13:54
Cookies Attributes
15:48
Cookies Attributes Overview
15:49
Common Cookies Attributes: Domain
16:24
Common Cookies Attributes: Path
17:04
Common Cookies Attributes: Expires
19:34
Coding Example: Setting Cookie Attributes
20:58
$_COOKIE Superglobal
27:03
$_COOKIE Superglobal
27:04
Coding Example: Accessing Cookies from PHP Using $_COOKIE
29:45
Security Implications
34:44
Security Implications
34:45
Homework Challenge
36:10
Homework Challenge: 1 - 4
36:11
Homework Challenge (cont.)
37:47
Homework Challenge: 5 - 7
37:48
Web Application Development

39m 11s

Intro
0:00
Lesson Overview
0:17
Lesson Overview
0:18
instanceof Operator
1:34
instanceof Operator
1:35
Objects with Object Properties
2:53
Objects with Object Properties
2:54
Version 11.0 Overview
6:41
Version 11.0 Changes: Cart and CartItem Classes
6:42
Version 11.0 Coding Example
10:40
Version 11.1 Overview
31:03
Version 11.1 Changes & Examples
31:04
Introduction to Sessions

46m 8s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
What is a Session?
0:53
What is a Session?
0:54
Client-Side Sessions
3:51
Client-Side Sessions
3:52
Server-Side Sessions
5:04
Server-Side Sessions
5:05
Session IDs
6:26
Session IDs
6:27
The SID is Used by the Server to:
7:08
A Client Passes an SID to the Server with Each HTTP Request Via:
8:15
Sessions in PHP
12:19
Sessions in PHP
12:20
session_start()
14:40
session_start() Overview
14:41
Coding Example: Using session_start () to Continue a Session
18:03
$_SESSION Superglobal
22:06
$_SESSION Superglobal Overview
22:07
Coding Example: Setting a Session Variable via $_SESSION
25:22
Accessing Session Data
28:08
Accessing Session Data
28:09
Deleting Session Data
31:43
Deleting Session Data
31:44
Coding Example: Deleting Session Data
32:16
Configuring PHP Sessions
36:14
session.cookie_lifetime, session.cookie_domain, and session.cookie_path
36:15
Coding Example: Configuring PHP Sessions
37:28
Configuring PHP Sessions (cont.)
40:56
session.use_cookies, session.use_trans_sid, and session.use_only_cookies
40:57
Coding Example: Configuring PHP Sessions
42:25
Homework Challenge
42:55
Homework Challenge: 1 - 5
42:56
Homework Challenge (cont.)
44:10
Homework Challenge: 6 - 10
44:11
Homework Challenge (cont.)
45:27
Homework Challenge: 11 - 13
45:28
Web Application Development

11m

Intro
0:00
Version 12.0 Overview
0:12
Version 12.0 Changes Part I: Updating 'viewCart.php' & 'checkout.php'
0:13
Version 12.0 Changes Part II
5:03
Destroying Sessions

29m 59s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Destroying Sessions
1:02
Destroying Sessions
1:03
session_destroy()
2:10
session_destroy() Overview
2:11
Coding Example: Setting a Session Variable and Destroying a Session
3:18
Deleting Session Cookies
8:38
Deleting Session Cookies
8:39
Coding example: Deleting Session Cookies
9:17
Review of Steps
21:07
Review of Steps
21:08
Garbage Collection
21:50
Garbage Collection Overview
21:51
Coding Example: Garbage Collection
24:30
Homework Challenge
26:28
Homework Challenge: 1 - 4
26:29
Homework Challenge (cont.)
28:16
Homework Challenge: 5 - 9
28:17
Web Application Development

19m 14s

Intro
0:00
Lesson Overview
0:13
Lesson Overview
0:14
_autoload()
0:46
Introduction to _autoload ()
0:47
Version 13.0 Overview
4:06
_autoload () and SessionManager Class
4:07
Updating 'viewCart.php' & 'checkout.php'
11:16
Introduction to Databases

21m 24s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
Flat Files
1:09
Flat Files: Definition and Example
1:10
Problems Associated with Using Flat Files as a Database
2:15
Relational Databases
3:29
Relational Databases
3:30
Relational Database Management System (RDBMS)
3:50
Tables
7:43
Tables
7:44
Columns
9:24
Columns
9:25
What is SQL?
10:45
Introduction to Structured Query Language
10:46
Standard Data Types of SQL
12:23
Primary Keys
13:19
Primary Keys
13:20
Primary Key Examples
16:36
Primary Key Examples
16:37
Introduction to MySQL

28m 11s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
What is MySQL?
1:33
MySQL
1:34
MySQL Monitor
5:16
MySQL Monitor Overview
5:17
XAMPP & MySQL
5:58
In the MySQL Command: hostname, username and -p
7:05
Connecting to a MySQl Server
9:52
Connecting to a MySQl Server
9:53
Using MySQl Monitor
13:48
Using MySQl Monitor
13:49
GRANT Command
15:10
GRANT SQL Command
15:11
Privileges & Objects
18:18
Username, Hostname, and Password
19:37
Specifying Objects
20:05
Creating a PHP User Account
21:41
Creating a PHP User Account Overview
21:42
Meaning of all & *.*
23:35
Example: Creating a PHP User Account
23:48
Required Homework
26:27
Required Homework: 1 - 5
26:28
Required Homework (cont.)
27:28
Required Homework: 6
27:29
Creating Databases & Tables

23m 1s

Intro
0:00
Lesson Overview
0:08
Lesson Overview
0:09
Creating a Database
1:40
Introduction to Creating a Database
1:41
Example: Creating a Database
3:33
CREATE TABLE Command
6:43
CREATE TABLE Command
6:44
Data Types
7:39
Numeric Data Types: INT, INT UNSIGNED, and DECIMAL
7:40
String Data Types: CHAR (M), VARCHAR (M), and TEXT
9:23
Colum Attributes
11:00
PRIMARY KEY Attribute
11:01
AUTO INCREMENT Attribute
11:35
Items Table
13:07
Items Table
13:08
Useful Commands
17:04
SHOW TABLES Command & DESCRIBE Utility Statement
17:05
Example: Creating an Items Table
17:58
Required Homework
20:51
Required Homework: 1 - 6
20:52
Required Homework (cont.)
21:55
Required Homework: 7 - 9
21:56
SQL Command: INSERT

27m 11s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
INSERT Command
1:20
SQL INSERT Command
1:21
Specifying Values
3:16
Columns with Numeric Data Types
3:17
Columns with String Data Types
3:34
Columns with AUTO INCREMENT
4:07
Inserting Items
5:21
Inserting Items
5:22
Example: Inserting Items
7:03
SQL Text Files
14:04
SQL Monitor Client
14:05
MySQL Monitor & the < Operator
15:15
Example
17:35
Required Homework
22:32
Required Homework: 1 - 6
22:33
Required Homework (cont.)
24:19
Required Homework: 7 - 10
24:20
SQL Command: SELECT

24m 57s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
SELECT Command
0:42
SELECT Command: Definition and Syntax
0:43
Results of a SELECT Query
1:53
To Specify the Retrieval of All Columns from a Table
3:06
Example: SELECT Command
4:18
WHERE Clause
7:11
WHERE Clause
7:12
A SELECT Query with WHERE Clause has the Following Syntax
8:10
A Where Condition can Contain both Logical and Comparison Operators
9:44
Literal Values
13:24
Literal Values
13:25
Example: Literal Values
14:18
ORDER BY Clause
15:31
ORDER BY Clause & SELECT Query
15:32
Ascending and Descending Order
17:30
An ORDER BY Clause can Specify Multiple Columns to Order the Rows by
18:01
Example: SELECT Query with WHERE and ORDER BY Clause
20:32
Homework Challenge
21:59
Homework Challenge
22:00
Homework Challenge (cont.)
23:54
Homework Challenge
23:55
Using PHP from MySQL

32m 43s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
PHP/MySQL Architecture
0:56
PHP/MySQL Architecture
0:57
MySQLi Extension
3:05
MySQLi Extension
3:06
Steps to Using MySQL from PHP
5:53
Four Steps to Using MySQL from PHP
5:54
Step # 3
7:18
Connecting to a Database
8:12
To Connect to a MySQL Database
8:13
To Test for Connection Errors
10:20
Running an SQL Statement
11:54
Running an SQL Statement
11:55
Example
13:30
Processing the Results
15:58
For non-SELECT Queries
15:59
MySQLi Object Property: affected_rows
16:19
For INSERT Statements on Tables with an AUTO_INCREMENT Column
18:07
Closing the Connection
19:45
Closing the Connection
19:46
Coding Example
21:24
Coding Example: Using MySQL from PHP
21:25
Homework Challenge
29:00
Homework Challenge: 1 - 4
29:01
Homework Challenge (cont.)
31:10
Homework Challenge: 5 - 9
31:11
Web Application Development

30m 30s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
sprintf()
1:28
sprintf() Overview
1:29
Example
1:56
INSERT Statements with sprintf()
5:15
INSERT Statements with sprintf()
5:16
Version 14.0 Overview
10:00
Version 14.0 Changes & Examples Part 1
10:01
Version 14.0 Changes & Examples Part 2
21:58
SELECT QUERIES from PHP

24m 22s

Intro
0:00
Lesson Overview
0:14
Lesson Overview
0:15
SELECT Queries
1:21
SELECT Queries
1:22
MySQLi_Result Class
3:17
MySQLi_Result Class: num_rows
3:18
MySQLi_Result Class: fetch_assoc ( ) and fetch_object ( )
3:59
fetch_assoc()
5:17
fetch_assoc() Overview
5:18
Coding Example: Using fetch_assoc()
9:00
stdClass Objects
12:46
stdClass Objects
12:47
fetch_object()
14:19
fetch_object() Overview
14:20
Coding Example: Using fetch_object()
16:45
Freeing Result Set Memory
18:42
Freeing Result Set Memory
18:43
Coding Example: Using free ( )
20:01
Homework Challenge
22:07
Homework Challenge: 1 - 5
22:08
Web Application Development

17m 6s

Intro
0:00
Version 15.0 Overview
0:13
Version 15.0 Changes & Examples Part 1
0:14
Version 15.0 Changes & Examples Part 2
8:43
Linking Tables

24m 32s

Intro
0:00
Lesson Overview
0:16
Lesson Overview
0:17
A Departments Table
1:08
Departments Table
1:09
How Could We Model This in a Table: Option 1
1:26
How Could We Model This in a Table: Option 2
3:12
Database Normalization
4:37
Database Normalization
4:38
Foreign Keys
8:47
Foreign Keys
8:48
Linking Table
11:26
Linking Table
11:27
Multiple Column Primary Keys
15:30
Multiple Column Primary Keys
15:31
Example
18:51
Required Homework
22:34
Required Homework: 1 - 3
22:35
Required Homework (cont.)
24:10
Required Homework: 4
24:11
Web Application Development

24m

Intro
0:00
Version 16.0 Overview
0:11
Version 16.0 Changes
0:12
Version 16.0 Coding Examples
4:12
Version 16.0 (cont.)
18:30
Version 16.0 Changes & Examples Part 2
18:31
SQL Command: DELETE

10m 33s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
DELETE Statement
0:30
DELETE Statement & Its WHERE Clause
0:31
Delete All Rows From a Table
2:57
Using DELETE from PHP
4:04
Using DELETE from PHP Overview
4:05
Coding Example: Using DELETE from PHP
6:37
Homework Challenge
8:53
Homework Challenge: 1 - 4
8:54
Web Application Development

16m 2s

Intro
0:00
Version 17.0 Overview
0:11
Version 17.0 Changes
0:12
Version 17.0 Coding Example
2:51
Transactions
12:50
Database Transaction
12:51
Steps in Using Transactions
14:00
SQL Command: UPDATE

32m 14s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
UPDATE Statement
0:54
UPDATE Statement & Its WHERE Clause
0:55
Example: UPDATE Statement
3:32
Using UPDATE from PHP
5:21
Using UPDATE from PHP Overview
5:22
Coding Example: Using UPDATE from PHP
6:53
htmlspecialchars()
9:04
htmlspecialchars()
9:05
Encoding Special Characters
9:23
Coding Example: htmlspecialchars()
13:41
addslashes()
20:40
addslashes()
20:41
Coding Example: addslashes()
22:52
Homework Challenge
27:55
Homework Challenge: 1 - 2
27:56
Homework Challenge (cont.)
30:14
Homework Challenge: 3 - 5
30:15
Homework Challenge (cont.)
30:41
Homework Challenge: 6 - 9
30:42
Web Application Development

12m 33s

Intro
0:00
Version 18.0 Overview
0:12
Version 18.0 Changes
0:13
Version 18.0 Coding Example
1:24
SQL: Joins

42m 16s

Intro
0:00
Lesson Overview
0:11
Lesson Overview
0:12
DATETIME Data Type
1:52
DATETIME Data Type
1:53
Modeling Orders
5:12
Modeling Orders
5:13
Customers Table
10:46
Customers Table
10:47
Example
16:18
Example: Order Table in MySQL
16:19
Joins
22:26
Joins Overview
22:27
Inner Join
23:09
Example: Joins
24:11
Join Conditions
28:14
Join Conditions
28:15
Example
28:32
Join Queries
30:00
Example: Join Conditions in MySQL
30:36
Implicit Joins
34:42
Implicit Joins
34:43
Example: Implicit Joins
35:57
Aliases
37:28
Introduction to Aliases
37:29
Example: Aliases
38:55
Required Homework
40:32
Problem 1
40:33
Problem 2
41:01
Problem 3
41:17
Web Application Development

29m 34s

Intro
0:00
Lesson Overview
0:12
Lesson Overview
0:13
Inserting Orders
0:44
Inserting Orders
0:45
Version 19.0 Overview
3:45
Version 19.0 Changes & Example Part 1
3:46
Version 19.0 Changes & Example Part 2
13:18
Version 19.1 Overview
21:10
Version 19.1 Changes
21:11
Version 19.1 Coding Example
22:18
User Authentication

26m 13s

Intro
0:00
Lesson Overview
0:10
Lesson Overview
0:11
User Authentication
1:31
User Authentication
1:32
Authentication with Sessions
2:34
Authentication with Sessions
2:35
Four Steps in Authentication via Sessions
2:50
Using Sessions to Restrict Access
3:58
Using Sessions to Restrict Access
3:59
Coding Example: Restricted Access Area
4:47
Authentication Methods
5:54
Authentication Methods Overview
5:55
Coding Example: Authentication Methods
7:31
Logging Out
9:57
Logging Out
9:58
Coding Example: Log Out
10:47
Users Table
13:50
Users Table
13:51
Example: Creating a Users Table
15:08
Password Hashing
17:30
Password Hashing
17:31
PHP and MySQL Built-in Hash Functions: sha1 ( ) and md5 ( )
18:43
Coding Example: Password Hashing
19:27
Required Homework
24:41
Required Homework: 1 - 4
24:42
Web Application Development

14m 36s

Intro
0:00
Version 20.0 Overview
0:13
Version 20.0 Changes & Examples Part 1
0:14
Version 20.0 Changes & Examples Part 2
5:05
Version 20.0 Changes & Examples Part 3
7:29
Version 20.0 (cont.)
8:31
Version 20.0 Changes & Examples Part 4
8:32
Loading...
This is a quick preview of the lesson. For full access, please Log In or Sign up.
For more information, please see full course syllabus of Advanced PHP
Bookmark & Share Embed

Share this knowledge with your friends!

Copy & Paste this embed code into your website’s HTML

Please ensure that your website editor is in text mode when you paste the code.
(In Wordpress, the mode button is on the top right corner.)
  ×
  • - Allow users to view the embedded video in full-size.
Since this lesson is not free, only the preview will appear on your website.
  • Discussion

  • Study Guides

  • Download Lecture Slides

  • Table of Contents

  • Transcription

  • Related Services

Lecture Comments (5)

0 answers

Post by Lily Truong on April 4, 2013

Thanx for this particular module. It is very useful. Would you know where I can learn about Stored Procedures in Educator.com?

1 answer

Last reply by: Matthew M.
Wed Apr 11, 2012 3:11 PM

Post by Herve Gnidehoue on February 10, 2012

Great explanation ! No doubt about it. Hats off

1 answer

Last reply by: Matthew M.
Tue Feb 7, 2012 3:38 AM

Post by ying zheng on January 27, 2012

Very clear.. thank you!

Introduction to Object-Oriented Programming

  • Object-oriented programming, or OOP, is a programming paradigm that allows user-defined data types to be created that model ‘real-world’ objects. Object-oriented programs work with and manipulate these 'objects'.
  • A class provides a formal description of how a particular real-world object is to be modeled in code. It is a ‘template’ for a user-defined data type.
  • A class can describe both the properties a particular type of object has, as well as any functions, known as methods, that a particular type of object can perform.
  • Classes are defined in PHP using the class keyword. Class names follow the same rules as variable names and by convention always have their first letter capitalized. Classes definitions also typically follow the one-class-per-file convention and have their definition file have the same name as the class.
  • An object refers to a particular instance of a class data type declared in PHP code.
  • Creating an object is known as instantiating, or creating an instance, of a class.
  • The new keyword is used to create an object, or an instance of, a class in PHP.
  • For objects of a particular class to be instantiated in a PHP script, the class definition file for those objects must be included or defined somewhere within the script.
  • An object’s properties can be set or accessed using the -> syntax.

Introduction to Object-Oriented Programming

Lecture Slides are screen-captured images of important points in the lecture. Students can download and print out these lecture slide images to do practice problems as well as take notes while watching the lecture.

  • Intro 0:00
  • Lesson Overview 0:11
    • Lesson Overview
  • Object-Oriented Programming 0:56
    • Introduction to Object-Oriented Programming
  • Associative Arrays 5:27
    • Associative Arrays
  • Classes 7:27
    • Classes Overview
  • Defining Classes 8:24
    • Defining Classes
    • Declaring Class Properties
    • Coding Example: Classes
  • Objects 12:18
    • Objects Overview
  • Classes vs. Objects 12:49
    • Classes vs. Objects
  • Instantiating Classes 14:58
    • Instantiating Classes
    • Coding Example: Instantiate an Item Object
  • Object Properties 19:21
    • Access and Set an Object's Property
    • Coding Example: Set & Access the Properties of an Item Object
  • Homework Challenge 30:22
    • Homework Challenge

Transcription: Introduction to Object-Oriented Programming

Hello again, and welcome back to Educator.com's Advanced PHP with MySQL course.0000

Today's lesson is a very exciting lesson, because we are going to be providing an introduction to object-oriented programming.0005

Specifically, we are going to talk a little bit about, just in general, what object-oriented programming is.0012

We are going to talk about how, in a way, we have been doing somewhat of a means of object-oriented programming through the use of associative arrays.0018

We are going to talk about what classes are and how to define them.0026

And then, we are going to talk about what objects are and the difference between classes and objects,0031

which is a common difficulty to understand for first-time students to object-oriented programming.0036

We are going to talk about what is known as instantiating classes, or creating objects.0043

And then, we are going to talk about how to get and set properties of an object we create.0048

Object-oriented programming is a paradigm of programming that allows you to work with objects in your code.0057

You take real-world objects, such as a person, and you model that in your code with user-defined data types.0068

And your programs work by manipulating and performing different functions on these different objects.0077

It is kind of an abstract concept, so it is maybe best explained by example.0085

As mentioned, for example, in the real world, there are people; and you have a person who has a first name and a last name.0090

Now, what we can do is take this real-world object, this person object, and model that in our code in a code object.0108

What we would do is create a user-defined data type that encapsulates information about that real-world object person.0117

So, we might create a class in our code that allows us to create what are known as person objects.0125

And a person object will have different attributes to it: you might have, for example, a first name attribute and a last name attribute.0135

What we do for object-oriented programming is take these real-world objects and model them in our code as a user-defined data type.0150

So, this person object is actually a user-defined data type that we are going to create, and that is known as creating a class.0158

Now, there are a number of benefits for using object-oriented programming,0167

one of which is that it makes your code a little bit easier to understand and talk about.0171

It is more intuitive to humans to talk about dealing with different objects (for example, a person object),0174

and saying, "I want to perform this operation on a person," as opposed to talking about integers and arrays.0181

Additionally, it is a way to pass around a related amount of data in one particular variable.0188

For example, one of the things we are going to be creating in our web application is a cart object that is going to represent a shopping cart in our store.0195

So, what we can do is: maybe we will have a method that will say, "Calculate total."0209

And we can pass it a (this isn't the proper syntax, but) cart object.0221

What that is going to allow us to do is: within that cart object, it is going to contain all of the information0229

about all of the items in the cart, what quantities they are, and so forth.0233

Now, this is as opposed to maybe (instead) having a calcTotal method where we have to provide0237

the item ID of each particular item, and the price of each particular item, and so forth.0246

And now, we can pass all that information in a cart.0255

Another way would be if we had an example that wanted to print out the name of a person.0258

We could just pass it a person object, and it could use that to extract the first name and last name of the person,0261

as opposed to having to pass two separate parameters, first name and last name.0269

One other thing to note, also: an important feature of objects is that not only can they contain data, but they also can have methods on them.0274

So, we could have this cart object that contains information about all of the items in our cart,0286

and in this cart object, we can do something called create methods, where the cart object will have a method called calcTotal.0291

What it is: we get a cart object in our code; we define it; we populate it with items;0304

and then, what we do is run this method on the cart object by itself, and it will calculate the total for us.0310

So, that is another benefit of using objects: they contain data, and then they also have methods and functions that they can operate on themselves with.0317

In a way, we have kind of been using object-oriented programming a little bit through the use of associative arrays.0328

As mentioned, one of the benefits of using objects is that you can encapsulate a number of different pieces of data--0336

for example, about a person--in one variable; you can create a person data type,0341

and then create a variable that is of that person data type.0347

And you just pass around that one variable, and you can access all of the information0350

(as we are going to see), such as the first name and the last name.0354

We have kind of been doing that with...for example, we have been using an array in our web application a lot called items.0357

And items has contained a number of keys (for example, itemID).0365

When we have a function that needs to operate on an item, we are just passing it this variable items.0371

So, in a way, we have already been doing that data encapsulation.0377

Now, what object-oriented programming does is gives us a formal way to declare what properties are part of an item.0380

For example, in our store items, we have a couple of different properties that we are using.0388

We have an item ID, a name, a price, a description, and an image file extension.0393

And the way we having been doing that is modeling that as an associative array, with a key for each of these0400

different properties of an item, and then setting a value to it.0405

But an associative array is just a general array that anybody can use.0409

You could add other key values to it; for example, you could just call something and assign a random key to it.0416

But what we are going to do is create a user-defined data type for an item.0425

We are going to create an item class, and that is going to allow us to create item objects.0429

And we will explain the difference between classes and objects in a little bit.0433

And what that is going to allow us to do is restrict what properties and what values a particular item object can have.0437

As mentioned, a class is a formal description of a particular real-world object that you are going to model in code.0449

It is essentially a template for a user-defined data type.0457

So, for a person, for example, we talked about the person object.0460

The person class would be a user-defined data type (it is something we can define in our code)0464

that says a person is an object that maybe contains two properties: it contains a first name and a last name.0470

And as mentioned, a class definition...when you create a user-defined data type, you can create properties in that class, such as first name and last name.0477

And then, as mentioned, you can also create methods, which we are not going to get into in today's lesson.0487

We are going to get into it in a future lesson.0492

That allows you to define methods that work on that particular object.0494

For example, for a cart object, you could say "calculate the total."0499

In PHP, the way you define a user-defined data type, which is called a class (and classes are used to create objects):0506

you use the class keyword; and class names in PHP follow the same rules as variable names, minus the dollar sign.0514

And by convention, they always have their first letter capitalized.0522

Additionally, the convention is: every time you define a new user-defined data type, you define it in its own file.0526

So, it follows a one-class-per-file convention.0533

And the PHP file that the class is defined in typically has the same name as the name of the class.0537

For example, if we are defining a Person class, we define it in its own file, and we are going to show what that looks like in a second.0546

And we are going to define it in a file called Person.php.0554

Typically, you also store your classes in, for example, a 'classes' subdirectory of your web application,0557

so that they all are located in one spot.0563

And then, what you can do is: when you define a class, you can define different properties.0566

For example, a person might have two different properties: it might have a first name and a last name.0570

Well, what you can do in a class is define properties using the syntax here of the public (which is a keyword),0575

followed by the variable name of the property you want to assign.0582

So, for any random object, we might have a property called property1.0585

We don't need to worry so much about the public keyword right now; we are going to talk a little bit more about that in future lessons.0591

But for now, we can just say that that is what we are going to be using to define our classes.0597

And when you define a property of a class, you can also provide it a default value.0601

For example, we could provide it a constant value, like the string literal value 1.0606

Let's take a look at a class we have created that is going to model an item in our store.0612

Here, we have a file called Item.php, because it is defining a class called Item.0617

We can see the class keyword here; we can see the name of the class immediately following the class keyword.0621

In this case, it's Item, and the first letter is capitalized.0627

And then, we can see that the class definition is located within a pair of curly braces.0630

What we have done here is defined a number of properties, which are also sometimes called attributes, or members, of a particular class.0636

We are saying that the Item class has five different properties.0644

One of them is going to be called itemID; and here is a comment for a programmer that is going to say that is going to represent the ID of the item.0648

It is going to have a property called name, a property called price, a property called description, and a property called imageFileExt.0656

These, again, over here, are just comments that describe to the programmer what these different properties are going to represent.0665

Here, what we have done is created our own user-defined data type.0672

We are saying, "We are creating a data type that is going to be called an Item, just as you would have an int or a float or a bool."0679

"Now, we have a new data type called item, and it is going to contain a number of different properties,"0687

"just as an array is a composite data type that can contain a number of different values in it."0693

And as we saw, we have been using associative arrays to hold a number of different data values for a particular item,0697

Now, we are saying we have this item data type, and it is going to contain a number of different pieces of data--0704

In this case, five particular pieces of data.0709

Now, this is valid PHP code; and you actually could go and load it in your browser.0712

If I go and load Item.php, it is not going to do anything, but it is PHP code, and it is what is called a class definition file.0716

And it tells PHP, when you create an instance of an Item class, what it is going to look like.0726

Objects refer to a particular instance of a class or a user-defined data type.0740

What an object is: it takes that class template (maybe that class template for Item you have created), and it fills in those values.0748

When you create an object, it is known as instantiating, or creating an instance of a class.0756

Let's take a look at a diagram that explains this a little bit better, that talks about classes versus objects.0769

Here we have a class; and this would be defined in our file, like in a class definition file, with the class keyword.0776

For example, let's say we define a class that is going to represent a person.0782

We are going to say that the person is going to have two properties, a first name and a last name.0788

Well, that Person class just defines what that data type will look like.0792

It is going to say that it is a data type that has two values: a first name and a last name.0796

Well, in our code, when we want to create a Person (it is called instantiating an object,0801

when we want to use a Person object), we have to create an instance of it.0810

And then, what it does is: we are assigning that data type to a variable and assigning values to it.0814

For example, when we create an instance of a class, we create what is known as an object.0823

And now, an object is going to be a PHP variable (here, for example, we are going to call it person1).0829

And an object is going to have the values of the class it is representing populated.0835

So, maybe we are going to create a Person object called person1 with the first name Joe and the last name Smith.0841

And maybe we will create another instance in our code of a Person object.0848

It is called person2, and we are going to assign the name Jane Jones to that object.0854

In a way, it is very similar to in PHP, where there is the int (or integer) data type that defines what an integer is.0859

PHP knows what it is, and so that is sort of like the class for an integer.0868

But any time you want to use an integer in your code, you create a variable, and you assign it a value.0872

In an analogous way, what this statement here is doing is: this is creating an object called int1 that is of the Integer class.0882

So, it is kind of something similar to what we have been doing, except we are using our own user-defined data types.0891

In PHP, the way that you instantiate a new class, or you create an object of a particular class, is using the new keyword.0900

And it has this form here.0907

So, what we do is: we declare a variable, and using an assignment operator, we have the new keyword,0909

followed by the name of the class we want to create an instance of, followed by opening and closing parentheses.0916

So, this line right here says, "Create the variable person1, and then set it to be an object of the Person class."0922

So, "Have it be of the data type that is represented by the Person class."0931

Now, one thing to note is that, if you were to run this within your script, PHP has to know what a Person class is.0938

It is not something that is defined in PHP.0948

For example, in our last example, we defined our Item object in a file called Item.php.0952

So, Person is going to be defined (by convention) in a file called Person.php, and it is going to provide that class definition for what a Person is.0957

Well, PHP needs to know about that in order for this statement to make sense.0967

Any time you use a particular class in a file, you need to either include this Person.php file,0970

or you can include the class definition with the script itself, which is not a recommended practice.0977

So, what we are always going to do is create our classes in separate files, and then include those within whatever scripts need them.0983

If we go and look at a script we call createItemObject.php, what this is going to do is instantiate (or create an instance of) our Item class.0992

Now, we defined our Item class as being a user-defined data type that has these five different properties to it.1002

Well, in createItemObject, the first thing we have done is: we have an include statement that says we are going to include this Item.php class definition file.1008

And here, we have sorted it in a subdirectory called classes, which is a common convention.1019

So now, our PHP has included Item.php, and it has that class definition for Item; it knows what Item is, so it can create an Item object.1024

Down here, what we do is create an instance of that class; we create an actual Item object.1034

We take the class, and we turn it into an object.1039

We are creating a variable called item1, and we are saying, "We are going to create this variable item1,1043

and it is going to be of the class type Item; so it is going to have the user-defined data type known as item."1048

Now, this right here doesn't do too much; but we are going to talk about properties in a second (which is going to show a little more).1055

This is code that just runs; it is not going to output anything.1061

But what it goes and does is loads that Item.php file, and then item1 is now an instance of that Item class.1065

We went and (it is not going to do anything, but) loaded it in our browser; we can see that it outputs this HTML header that we had in the file.1075

But it doesn't really do anything; but it shows that the code was appropriately run.1085

Now, as mentioned, you have to have the class definition file included within a script, where you are creating an instance of that class.1090

For example, here we are creating an instance of the class Item; we had to include the class definition file for item.php.1101

If not, PHP doesn't know how to declare it.1107

Let's say we misspell this, and we include a file called item3.php.1109

Well, now when PHP gets down here and tries to create an Item class, it is not going to know what it is,1114

because it hasn't included the appropriate file, Item.php.1120

For example, now, if we save this, and we go and run the script again, we can see a couple of things.1125

One is that we get a warning that says item3.php could not be found.1132

But the one we are more interested in for this particular lesson is: it says, "Class Item is not found."1137

It is saying, on line 20 (if we look back at our code), "You tried to create an instance of the Item class, but we don't know what the Item class is."1142

And so, that is where this error message comes in here: "Class Item not found."1156

One of the things that objects have, that we mentioned that classes have, is: they define properties that a particular object of that class can have.1163

For example, a Person object, or a Person class, might have two properties: a first name and a last name.1171

Well, in PHP, there is a special syntax that is used: it is a dash followed by a greater than sign1180

that allows you to set, and then also get, the values of a particular object's properties.1186

So, after you have already created an object--after you have done something like item1=new,1192

which is the keyword used to create a new instance of an item object,1202

if we wanted to set a particular property of this item, we use this notation here.1208

So, what we do is: we have the name of the object variable that we created using the new method.1217

We have this dash followed by a greater than sign, and then the property that we want to set followed by the value.1225

For example, we know, in our Item class, we have a name property.1232

So, if we wanted to set the name of our Item object that we created, we say item1 (which is the variable1236

that refers to the new item object that we have created--so it's an actual object);1244

we use this operator--the dash followed by the greater than sign, followed by the name of the property we want to set.1248

If we look back at our Item.php, it has a property called name.1257

And then, we are going to set it equal to maybe the string Basketball.1267

So now, what we have done is set the name property that is associated with this item1 object.1273

Now, one thing to note is that a class defines the data type of a user-defined data type; it defines what values it can have.1284

However, when we create a new object, it creates a whole new instance of that class.1294

For example, if we went down here, and we defined a new Item called item2, and we set it equal to an Item object,1301

this item2 has its own copy of the name property, so we can go down here and set the name of the item2 Item to Other--to something else.1317

Now, we have two objects that are of the Item class type (the Item data type).1336

And each one of those objects has their own copy of the properties defined.1344

This is how we represent different items in our code.1350

This is going to be item #1, that has the name Basketball; this is going to be item #2 that has the name Other.1352

And then, what we can do is (let me erase some of this here): we can also use that same - sign,1360

followed by the greater than sign, to access a particular object's property.1367

For example, we might want to echo this name property.1373

And the way you would do that would be: you get the object name, item1; then you have this dash sign,1377

followed by the greater than sign, and then the name of the property you want to get the value of.1386

In this example here, this is saying, "For the item1 object, go and retrieve the value associated with the name property for that item."1395

Now, in our other example that I just erased...1406

In this case, what it is going to do is echo 'Basketball.'1410

Now, if we had run this same code on that Item we had just created (let's assume it was still here, up in this section);1414

if we had done, instead, item2, dash, greater than, name, what would be output would be 'Other.'1420

And that is because each Item object that we create has its own set of all of those properties defined in the Item class.1431

So, every time that we instantiate class Item using the new keyword, we create a variable, and we assign it this Item class type,1439

it gets its own version of all of these different properties.1448

Each one has its own itemID, its own name, its own price.1453

And the way you access and set those is using the dash, followed by the greater than sign.1456

Let's take a look at accessing and setting properties in action.1464

We have a script called itemObjectProperties.php that has the same beginning as our last script.1469

We include the Item class definition; we instantiate--we create a new Item object, and we set it equal to this variable item1.1476

And then, now we are going to go through and set all of the different properties of this Item, using this dash, greater than operator.1488

We are going to say, for item1 (which is this new Item object we have created), we are going to set its itemID to 1001.1494

We are going to set its name equal to Baseball, its price to $4.99, its description to this, and its extension equal to that.1501

And then, what we are going to do is access these different properties.1508

Now that we have set them, we can extract the values from that particular Item object.1512

So, on that Item object, we are going to extract all of the values into separate variables.1517

We are going to say, "Set a variable called itemID equal to the item ID that the Item object associated with the variable item1 has."1523

The key thing here is that it's the itemID associated with the item1 instance of an object.1535

In our last example, if this had been item2, the item ID could be the same, but typically it would be something different.1540

The key here is that, when you are accessing a property of a particular object,1548

you are accessing the properties of a particular instance of that object.1553

In this case, we are accessing the item1 instance of the object.1557

We go ahead and extract all of the different properties, using this dash, greater than sign.1561

And then, we just go ahead and output that.1569

If we go ahead and look at this code in our browser, itemObjectProperties.php,1572

we can see that what it has done is gone and, after having set all those properties, output all of the different values that we had set.1577

Now, one thing to notice is that...let's say we tried this code before we set any of the properties--1586

before we performed this set operation up here; well, our Item class, when it is initially created, doesn't have any values for these.1594

So, when this is run, when you try to access itemID, it is not going to return anything, because no value for that exists.1603

It, in fact, is null; so if we go ahead and save that script and reload it,1611

we can see that, the first time we try to access the information associated with the item1 object1616

(which is an object of the Item class), no values are set.1622

Now, as mentioned in our class definition, we can include default values.1627

So, let's say, for example, that we set a default value for the name property of an Item class.1631

And we will just call it default; so any time we create a new object that is of the class Item, it is going to have five different properties.1643

And the property name is going to have the value set to default.1654

And then, any other properties--you have to have manually set them, in order to have them set a value.1660

Now, you can overwrite this default property, which is what you would do, using that dash, greater than operator.1664

But at least, when this object starts, it has a default property.1672

So now, we go back and look at our code here.1674

After we have created this new Item object, and we try to retrieve all of its different properties,1678

this one for name is going to return that name 'default,' because it is already set when you create this Item class.1686

Before you set any properties to it, it already has a default value provided.1697

So, when we output this information before we have set all of the other values, it is going to output that name.1700

If we go and look at our code now, we can see that up here, it output the name 'default.'1706

And that is because we had provided a default value for it.1711

And so, you can see, also, that we were able (down here) to rename the object item1 to Baseball,1717

so that when we output the information for this object a second time, we can see that default has been changed to Baseball.1725

One of the key things to note is the difference between classes and objects;1737

and that is a very complex concept when you are first starting to work with object-oriented programming.1741

Just to reiterate, a class is the template for a user-defined data type that you are creating.1749

You are saying, "I am creating an item class, and it is going to have 5 different properties," for example.1756

Now, any time you want to create a variable that is of that class, you instantiate it using the new keyword.1762

You are creating a new variable that contains all 5 of those properties--for example, for the Item object.1769

And every time you call this new Item object, it creates a whole new copy of all of those properties.1779

So, when we call item2--if we set this to item2=new Item(), item2, again, is going to have its own copy of all of those different properties.1787

So, the class just describes the structure of what an Item object looks like.1798

When you create an instance of the class using the new keyword, it creates spots in memory for all the different properties of that.1804

And you can set them; and each object you create has its own copy of those,1813

and you can set and change them as you need, during the course of your script.1817

For the homework challenge for today, I just want you to create a class called Address that represents a street address.1824

It should have four properties: street, city, state, and zipcode (which represent the different parts of this real-world object).1830

For example, you could have an abstract model of an address, and you could say,1841

"We are going to model this address in our code as something that has these four parts to it."1845

Then, you do that in its own class definition file, and then, in a separate script, create an instance of the Address class using the new keyword.1850

And then, set values for all four of the properties of that object, using the dash, greater than syntax.1861

Then, like we did in the example, use the same dash, greater than syntax1873

to access the values that you have set for those particular properties and output them.1878

So, you can see that you were able to define the class appropriately,1884

that you were able to know how to set the properties of the class,1890

and also that you were able to access those properties of the class.1893

Be sure, when you do this, that you follow the one-class-per-file convention,1896

which means that you are going to define Address in its own file, called Address.php.1901

And remember that, in your script, when you create an instance of the Address object,1905

that you include that class definition file within your script.1913

That way, PHP knows what an Address class data type is.1917

And then also, just make sure (and we will get to this in future lessons) that when you define your properties1924

in your class definition file, you precede them with the public keyword.1930

And again, if we look at our Item.php, within the curly braces of this class's definition,1935

you have the public keyword, followed by a variable name1943

for a particular property you want that object to have, followed by a semicolon.1948

So, here we have five different statements that declare properties for that particular class.1952

That ends today's lesson; thank you for watching Educator.com--I look forward to seeing you next time.1959

Educator®

Please sign in to participate in this lecture discussion.

Resetting Your Password?
OR

Start Learning Now

Our free lessons will get you started (Adobe Flash® required).
Get immediate access to our entire library.

Membership Overview

  • Available 24/7. Unlimited Access to Our Entire Library.
  • Search and jump to exactly what you want to learn.
  • *Ask questions and get answers from the community and our teachers!
  • Practice questions with step-by-step solutions.
  • Download lecture slides for taking notes.
  • Track your course viewing progress.
  • Accessible anytime, anywhere with our Android and iOS apps.