1 / 22

PHP

PHP. By Sergio Rodriguez. PHP. PHP: Hypertext Preprocessor Scripting language. History. 1994 - Written by Rasmus Lerdorf 1997 - Zeev Suraski and Andi Gutmans Rewrote parser PHP 2. History. 1998 - PHP 3 2000 - PHP 4 Still being developed Version 4.4.7 - Oct. 2007 2004 - PHP 5.

hope
Download Presentation

PHP

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP By Sergio Rodriguez

  2. PHP • PHP: Hypertext Preprocessor • Scripting language

  3. History • 1994 - Written by Rasmus Lerdorf • 1997 - Zeev Suraski and Andi Gutmans • Rewrote parser • PHP 2

  4. History • 1998 - PHP 3 • 2000 - PHP 4 • Still being developed • Version 4.4.7 - Oct. 2007 • 2004 - PHP 5

  5. Usage • Server-side Scripting • Web development • Command-line Scripting • Shell scripting • Client-side GUI Apps • Not very common

  6. Server-side Scripting • Main use • Code embedded in HTML to create dynamic web pages • LAMP Architecture • Advantage over others…$$$ …but first!

  7. Syntax • Advantage: Similar to high level PL’s we are familiar with • PHP code goes between tags • <?php --CODE-- ?> • Features that make it different

  8. Syntax • Embedding HTML in PHP control structures • Will output anything between ?> and the next <?php tags

  9. Types • 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)

  10. Types Eight different types: • Boolean • Integer • Float AKA Double • String • Array • Object • Resource • Null

  11. Boolean • Trivial • Cast as (bool) or (boolean) • False is: • Integer - 0 • Float - 0.0 • String - Empty or “0” • NULL • Array - Size = 0 … among others • True is everything else

  12. Integer • No unsigned integers in PHP • Include octal and hexadecimal numbers • Octal - 0[0-7]+ • Hex - 0[xX][0-9a-fA-F]+ • Overflow? Treats value as float • No division operator - yields float • Cast as (int) or (integer) • From float to integer - rounding towards zero

  13. Float (Double) • Loss of precision when converted to internal binary • Ex: floor((0.1+0.7)*10) is 7, not 8 • Cast as (float), (double), or (real)

  14. String • No bound to size of strings • Single quotes • Escape ‘ or \ characters • Double quotes • More escaped characters (\n, \t, \\, etc)

  15. Array • (key, value) pairs • Key may be an integer index, like Java arrays • print_r($arr); //Prints out array

  16. Object • Use “new” to create new instance • Cast as (object) - new instance of built-in class stdClass • “scalar” member contains value

  17. Resource • “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)

  18. Variables • Start with $, followed by underscore or letter, and then followed by (number | letter | underscore)* • Dynamic Scoping • Variable variables • Hold variable name as string

  19. Operators • Same as other PL’s • ===, !== • echo `shell command` • . (Yeah, that’s it) • Arrays • +, and equality across key/value pairs • Instanceof (Looks familiar?)

  20. Functions • Again, similar to what we already know • C++-style • i.e. function foo($myVal = 44){/*BODY*/} • return arrays to list • Store function name in variable

  21. Objects • Nothing new • parent - used in inheritance, refers to base class • PHP 5 is more extensive

  22. References • Wikipedia - PHP • http://en.wikipedia.org/wiki/PHP • PHP Manual • http://www.php.net/manual/en/index.php

More Related