php by sergio rodriguez by sergio rodriguez. php g php: hypertext preprocessor g scripting language...

22
PHP By Sergio Rodriguez

Upload: caroline-lindsey

Post on 13-Jan-2016

246 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

PHPPHP

BySergio Rodriguez

BySergio Rodriguez

Page 2: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

PHPPHP

PHP: Hypertext Preprocessor

Scripting language

PHP: Hypertext Preprocessor

Scripting language

Page 3: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

HistoryHistory

1994 - Written by Rasmus Lerdorf

1997 - Zeev Suraski and Andi GutmansRewrote parserPHP 2

1994 - Written by Rasmus Lerdorf

1997 - Zeev Suraski and Andi GutmansRewrote parserPHP 2

Page 4: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

HistoryHistory

1998 - PHP 3

2000 - PHP 4Still being developedVersion 4.4.7 - Oct. 2007

2004 - PHP 5

1998 - PHP 3

2000 - PHP 4Still being developedVersion 4.4.7 - Oct. 2007

2004 - PHP 5

Page 5: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

UsageUsage

Server-side ScriptingWeb development

Command-line ScriptingShell scripting

Client-side GUI AppsNot very common

Server-side ScriptingWeb development

Command-line ScriptingShell scripting

Client-side GUI AppsNot very common

Page 6: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

Server-side ScriptingServer-side Scripting

Main useCode embedded in HTML to create

dynamic web pagesLAMP Architecture

Advantage over others…$$$

…but first!

Main useCode embedded in HTML to create

dynamic web pagesLAMP Architecture

Advantage over others…$$$

…but first!

Page 7: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

SyntaxSyntax

Advantage: Similar to high level PL’s we are familiar with

PHP code goes between tags<?php --CODE-- ?>

Features that make it different

Advantage: Similar to high level PL’s we are familiar with

PHP code goes between tags<?php --CODE-- ?>

Features that make it different

Page 8: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

SyntaxSyntax

Embedding HTML in PHP control structures

Will output anything between ?> and the next <?php tags

Embedding HTML in PHP control structures

Will output anything between ?> and the next <?php tags

Page 9: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

TypesTypes

Type is not explicitly set for variable by programmer

Type of variable is “juggled” throughout PHP code

Criticism due to this (errors not detected at compile time)

Type is not explicitly set for variable by programmer

Type of variable is “juggled” throughout PHP code

Criticism due to this (errors not detected at compile time)

Page 10: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

TypesTypes

Eight different types: Boolean Integer Float AKA Double String Array Object Resource Null

Eight different types: Boolean Integer Float AKA Double String Array Object Resource Null

Page 11: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

BooleanBoolean

Trivial Cast as (bool) or (boolean) False is:

Integer - 0Float - 0.0String - Empty or “0”NULLArray - Size = 0 … among others

True is everything else

Trivial Cast as (bool) or (boolean) False is:

Integer - 0Float - 0.0String - Empty or “0”NULLArray - Size = 0 … among others

True is everything else

Page 12: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

IntegerIntegerNo unsigned integers in PHPInclude octal and hexadecimal

numbersOctal - 0[0-7]+Hex - 0[xX][0-9a-fA-F]+

Overflow? Treats value as floatNo division operator - yields floatCast as (int) or (integer)From float to integer - rounding

towards zero

No unsigned integers in PHPInclude octal and hexadecimal

numbersOctal - 0[0-7]+Hex - 0[xX][0-9a-fA-F]+

Overflow? Treats value as floatNo division operator - yields floatCast as (int) or (integer)From float to integer - rounding

towards zero

Page 13: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

Float (Double)Float (Double)

Loss of precision when converted to internal binary

Ex: floor((0.1+0.7)*10) is 7, not 8Cast as (float), (double), or (real)

Loss of precision when converted to internal binary

Ex: floor((0.1+0.7)*10) is 7, not 8Cast as (float), (double), or (real)

Page 14: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

StringString

No bound to size of strings

Single quotesEscape ‘ or \ characters

Double quotesMore escaped characters (\n, \t, \\, etc)

No bound to size of strings

Single quotesEscape ‘ or \ characters

Double quotesMore escaped characters (\n, \t, \\, etc)

Page 15: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

ArrayArray

(key, value) pairs

Key may be an integer index, like Java arrays

print_r($arr); //Prints out array

(key, value) pairs

Key may be an integer index, like Java arrays

print_r($arr); //Prints out array

Page 16: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

ObjectObject

Use “new” to create new instanceCast as (object) - new instance of

built-in class stdClass“scalar” member contains value

Use “new” to create new instanceCast as (object) - new instance of

built-in class stdClass“scalar” member contains value

Page 17: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

ResourceResource

“A resource is a special variable, holding a reference to an external resource.” Taken from the PHP Documentation

i.e. Connectors to DBs (mySQL, MSSQL, etc)

“A resource is a special variable, holding a reference to an external resource.” Taken from the PHP Documentation

i.e. Connectors to DBs (mySQL, MSSQL, etc)

Page 18: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

VariablesVariables

Start with $, followed by underscore or letter, and then followed by (number | letter | underscore)*

Dynamic Scoping

Variable variablesHold variable name as string

Start with $, followed by underscore or letter, and then followed by (number | letter | underscore)*

Dynamic Scoping

Variable variablesHold variable name as string

Page 19: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

OperatorsOperators

Same as other PL’s===, !==echo `shell command`. (Yeah, that’s it)Arrays

+, and equality across key/value pairsInstanceof (Looks familiar?)

Same as other PL’s===, !==echo `shell command`. (Yeah, that’s it)Arrays

+, and equality across key/value pairsInstanceof (Looks familiar?)

Page 20: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

FunctionsFunctions

Again, similar to what we already know

C++-stylei.e. function foo($myVal =

44){/*BODY*/}return arrays to listStore function name in variable

Again, similar to what we already know

C++-stylei.e. function foo($myVal =

44){/*BODY*/}return arrays to listStore function name in variable

Page 21: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

ObjectsObjects

Nothing newparent - used in inheritance, refers

to base class

PHP 5 is more extensive

Nothing newparent - used in inheritance, refers

to base class

PHP 5 is more extensive

Page 22: PHP By Sergio Rodriguez By Sergio Rodriguez. PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language

ReferencesReferences

Wikipedia - PHPhttp://en.wikipedia.org/wiki/PHP

PHP Manualhttp://www.php.net/manual/en/index.

php

Wikipedia - PHPhttp://en.wikipedia.org/wiki/PHP

PHP Manualhttp://www.php.net/manual/en/index.

php