Download presentation
Presentation is loading. Please wait.
Published byCaroline Lindsey Modified over 9 years ago
1
PHP By Sergio Rodriguez By Sergio Rodriguez
2
PHP G PHP: Hypertext Preprocessor G Scripting language G PHP: Hypertext Preprocessor G Scripting language
3
History G 1994 - Written by Rasmus Lerdorf 1997 - Zeev Suraski and Andi Gutmans Rewrote parser PHP 2 G 1994 - Written by Rasmus Lerdorf 1997 - Zeev Suraski and Andi Gutmans Rewrote parser PHP 2
4
History G 1998 - PHP 3 G 2000 - PHP 4 G Still being developed G Version 4.4.7 - Oct. 2007 G 2004 - PHP 5 G 1998 - PHP 3 G 2000 - PHP 4 G Still being developed G Version 4.4.7 - Oct. 2007 G 2004 - PHP 5
5
Usage G Server-side Scripting G Web development G Command-line Scripting G Shell scripting G Client-side GUI Apps G Not very common G Server-side Scripting G Web development G Command-line Scripting G Shell scripting G Client-side GUI Apps G Not very common
6
Server-side Scripting G Main use G Code embedded in HTML to create dynamic web pages G LAMP Architecture G Advantage over others…$$$ …but first! G Main use G Code embedded in HTML to create dynamic web pages G LAMP Architecture G Advantage over others…$$$ …but first!
7
Syntax G Advantage: Similar to high level PL’s we are familiar with G PHP code goes between tags G G Features that make it different G Advantage: Similar to high level PL’s we are familiar with G PHP code goes between tags G G Features that make it different
8
Syntax G Embedding HTML in PHP control structures G Will output anything between ?> and the next <?php tags G Embedding HTML in PHP control structures G Will output anything between ?> and the next <?php tags
9
Types G Type is not explicitly set for variable by programmer G Type of variable is “juggled” throughout PHP code G Criticism due to this (errors not detected at compile time) G Type is not explicitly set for variable by programmer G Type of variable is “juggled” throughout PHP code G Criticism due to this (errors not detected at compile time)
10
Types Eight different types: G Boolean G Integer G Float AKA Double G String G Array G Object G Resource G Null Eight different types: G Boolean G Integer G Float AKA Double G String G Array G Object G Resource G Null
11
Boolean G Trivial G Cast as (bool) or (boolean) G False is: G Integer - 0 G Float - 0.0 G String - Empty or “0” G NULL G Array - Size = 0 … among others G True is everything else G Trivial G Cast as (bool) or (boolean) G False is: G Integer - 0 G Float - 0.0 G String - Empty or “0” G NULL G Array - Size = 0 … among others G True is everything else
12
Integer G No unsigned integers in PHP G Include octal and hexadecimal numbers G Octal - 0[0-7]+ G Hex - 0[xX][0-9a-fA-F]+ G Overflow? Treats value as float G No division operator - yields float G Cast as (int) or (integer) G From float to integer - rounding towards zero G No unsigned integers in PHP G Include octal and hexadecimal numbers G Octal - 0[0-7]+ G Hex - 0[xX][0-9a-fA-F]+ G Overflow? Treats value as float G No division operator - yields float G Cast as (int) or (integer) G From float to integer - rounding towards zero
13
Float (Double) G Loss of precision when converted to internal binary G Ex: floor((0.1+0.7)*10) is 7, not 8 G Cast as (float), (double), or (real) G Loss of precision when converted to internal binary G Ex: floor((0.1+0.7)*10) is 7, not 8 G Cast as (float), (double), or (real)
14
String G No bound to size of strings G Single quotes G Escape ‘ or \ characters G Double quotes G More escaped characters (\n, \t, \\, etc) G No bound to size of strings G Single quotes G Escape ‘ or \ characters G Double quotes G More escaped characters (\n, \t, \\, etc)
15
Array G (key, value) pairs G Key may be an integer index, like Java arrays G print_r($arr); //Prints out array G (key, value) pairs G Key may be an integer index, like Java arrays G print_r($arr); //Prints out array
16
Object G Use “new” to create new instance G Cast as (object) - new instance of built-in class stdClass G “scalar” member contains value G Use “new” to create new instance G Cast as (object) - new instance of built-in class stdClass G “scalar” member contains value
17
Resource “ A resource is a special variable, holding a reference to an external resource. ” Taken from the PHP Documentation G 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 G i.e. Connectors to DBs (mySQL, MSSQL, etc)
18
Variables G Start with $, followed by underscore or letter, and then followed by (number | letter | underscore)* G Dynamic Scoping G Variable variables G Hold variable name as string G Start with $, followed by underscore or letter, and then followed by (number | letter | underscore)* G Dynamic Scoping G Variable variables G Hold variable name as string
19
Operators G Same as other PL’s G ===, !== G echo `shell command` G. (Yeah, that’s it) G Arrays G +, and equality across key/value pairs G Instanceof (Looks familiar?) G Same as other PL’s G ===, !== G echo `shell command` G. (Yeah, that’s it) G Arrays G +, and equality across key/value pairs G Instanceof (Looks familiar?)
20
Functions G Again, similar to what we already know G C++-style G i.e. function foo($myVal = 44){/*BODY*/} G return arrays to list G Store function name in variable G Again, similar to what we already know G C++-style G i.e. function foo($myVal = 44){/*BODY*/} G return arrays to list G Store function name in variable
21
Objects G Nothing new G parent - used in inheritance, refers to base class G PHP 5 is more extensive G Nothing new G parent - used in inheritance, refers to base class G PHP 5 is more extensive
22
References G Wikipedia - PHP G http://en.wikipedia.org/wiki/PHP http://en.wikipedia.org/wiki/PHP G PHP Manual G http://www.php.net/manual/en/index.ph p http://www.php.net/manual/en/index.ph p G Wikipedia - PHP G http://en.wikipedia.org/wiki/PHP http://en.wikipedia.org/wiki/PHP G PHP Manual G http://www.php.net/manual/en/index.ph p http://www.php.net/manual/en/index.ph p
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.