Transcript Slides
Presented by: Tyler Roberts
What is PHP?
PHP is a general purpose server-side scripting
language designed for web development.
Used to help provide dynamic web pages
Usually embedded in HTML code, but can also be
standalone
What you need for PHP
development
Hosting software (for local hosting you can use
something like XAMPP)
Any text editor
An internet browser
Hello World!
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
</body>
</html>
History
Created in 1994 by Rasmus Lerdorf and released to the
public in June of 1995
The original versions of PHP were written in the C
programming language.
Because of the source code being released to the public for
improvement it was later equipped with more features and
functionality.
Was named PHP/FI
PHP 3
Students from Tel Aviv, Andi Gutmans and Zeev
Suraski began doing a code rewrite of PHP on their
own in 1997.
Gutmans, Suraski, and Rasmus (the original creator of
PHP) started working together to develop a new
programming language, PHP: Hypertext Preprocessor.
PHP 3
In 1998 the use of PHP began to spread and was being
used on 10% of web servers, up from 1% in the previous
year.
As soon as PHP 3.0 was released, Gutmans and
Suraski were already working on a rewrite of PHP.
PHP 4 and PHP 5
PHP 4 released in 2000
Support for more web servers, HTTP sessions, output
buffering, and several new language constructs
Currently PHP is on version 5.6 and roughly 82% of
known websites use it for server side programming.
Variable names, bindings, and
scopes
Case sensitive
Must be preceded by a ‘$’
Valid variables start with a letter or ‘_’ and then
followed by any number of letters, numbers, or
underscores
Names, bindings, and scopes
Contains keyword “global” that lets users access global versions
of variables that may have a variable of the same name in a
function
Example:
<?php
$a = 1;
$b = 2;
function Sum()
{
global $a, $b;
$b = $a + $b;
}
Sum();
echo $b;
?>
Names, bindings, and scopes
Static variable exists on in a local function’s scope, it
doesn’t lose it’s value when execution leaves the scope.
Example:
<?php
function test()
{
static $a = 0;
echo $a;
$a++;
}
?>
Data Types
Eight different data types:
Boolean
Integer
Float
String
Array
Object
Resource
NULL
Assignment Operators
x=y
x += y or x + y
x -= y or x – y
x *= y
or x * y
x /= y or x / y
x %= y or x % y
Comparison Operators
Equal
==
Identical
===
Not Equal
!= or <>
Not Identical
!==
Greater than
>
Less than
<
Greater than or equal to
>=
Less than or equal to
<=
Other Operators
Increment by one, then
return $x
++$x
Return $x, then increment
by one
$x++
Decrement by one, then
return $x
--$x
Return $x, then decrement
by one
$x--
And
‘and’ or &&
Or
‘or’ or ||
Xor
‘xor’
not
!
Statement level control structures
If
Else
Elseif
While
Do-while
For
Foreach (used for iterating through array or object)
Switch
Subprograms
Defined by using the “include” or “required”
statements
This lets programmer use parts from multiple .php
files
When a file is included, the code it contains inherits
the variable scope on the line on which the include
occurs.
Abstract data types and Exception
Handling
Has support for stack and queue abstract data types
Exception handling follows the common scheme used
in most languages
Can be thrown, caught, and surrounded in a try
statement
PHP specifics
Some predefined variables that are used in PHP that
might not be so familiar are:
$_GET – HTTP GET variables
$_POST –HTTP POST variables
$_COOKIE – HTTP Cookies
$argv –Array of arguments passed to the script
Readability
If written correctly PHP is relatively easy to read.
Almost all of the standard programming language
essentials have a very familiar syntax
If coder has basic coding knowledge they would be
able to read most PHP code without even doing any
research.
Writability
Basic PHP coding is extremely easy to write.
Once the coder gets into the more complex back-end
coding they might need to research because the main
purposes of PHP are very specific.
If the coder isn’t familiar with communicating with
databases and other web services (via GET and POST)
they might get lost.
Cost
PHP is open source and can be written in any basic text
editor. It also can be hosted for free.
The two things that seem to affect the cost of PHP the
most are:
Difficulty of debugging
Reputation of the “open source” solution
Code Example:
https://bitbucket.org/tanagerproductions/tanager-
marketingwebsite/src/07d5ed044e5dc7a3686ceb6a3f1779507cb8
815d/contact_form.php?at=master
Questions?