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

Post on 13-Jan-2016

241 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

PHPPHP

BySergio Rodriguez

BySergio Rodriguez

PHPPHP

PHP: Hypertext Preprocessor

Scripting language

PHP: Hypertext Preprocessor

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

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

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

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!

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

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

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)

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

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

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

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)

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)

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

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

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)

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

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?)

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

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

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

top related