180 likes | 363 Views
Php5. CSE301 Harry Erwin, PhD. Topics. What is PHP5? Description Security Syntax Object-Orientation Speed Compilers Resources. Sources. Wikipedia Programming PHP by Lerdorf and Tatroe. What is PHP5?.
E N D
Php5 CSE301 Harry Erwin, PhD
Topics • What is PHP5? • Description • Security • Syntax • Object-Orientation • Speed • Compilers • Resources
Sources • Wikipedia • Programming PHP by Lerdorf and Tatroe
What is PHP5? • A widely-used, general-purpose scripting language originally intended to support dynamic web page development. • Can be imbedded into HTML pages using the same approach as JSP or ASP pages. • The webserver needs to install a PHP processor module. • Also supports general purpose scripting. • Imperative, procedural, object-oriented, and reflective. • The latest version is 5.3.5 (which fixed a critical vulnerability).
Usage • Primarily supports web applications and server-side web development. • Mediawiki • PHPwiki • Wordpress • PHPblog • Operates as a filter, taking input from a file or stream and outputting another stream of data. • Does support bytecode processing by the Zend engine. • Part of the LAMP framework.
Security • Historically has been a problem. • Currently improving. • Mostly due to sloppy programming rather than language or library weaknesses. • Does not provide taint checking to detect lack of input validation. • Careful and constant attention is necessary.
Syntax • Within HTML, XHTML, and XML, PHP code is delimited by <?php and ?>. Alternatively, <script language=“php”></script> or short delimiters. • Variables are identified by leading $. No type. • Handles are $$name. • References handled as $black =& $white • Function and class names, built-in constructs, and keywords are not case-sensitive; variable names are. • stdClass is a reserved class name.
More Syntax • Variables can be imbedded into strings. • Newlines are whitespace • Statements terminated by semicolon • Blocks delimited by {}. Semicolon before } is mandatory. • Semicolon before closing tag is optional but wise. • Java-style comments • echo writes text • Keywords and syntax similar to other C-style languages
Data Types • Eight types: • integers, • floating point numbers, • strings, • booleans, • arrays, leading position is 0, or by name • objects, • resource, • NULL • Integers are platform-dependent (32/64 bits) • Integers can be written as decimal, octal, or hexadecimal • Unsigned integer conversion is unusual. • Generally similar to C++
Scope • Local defined within a function • Global defined outside functions • Static static $counter will persist within a function • Function (named parameters)
Loopiness • foreach($person as $name) uses $name; $person is the array • Otherwise similar to C++
Functions • Over the top. • See the PHP site. • Lots of naming conventions and inconsistencies. • No thread programming • Syntax simplified from C. • function myFunction() { return foo;} • In 5.3, functions are first class objects and anonymous functions are supported
Including Code • require ‘filename’ • include ‘filename’ (if available) • filename can start with http:// or ftp://
Object-Orientation • Major rewrite in PHP5 • Objects referenced by handle and not by value (pointer to pointer) • Now similar to Java. • $object = new Class; • Or • $class = ‘Person’; • $object = new $class; • -> syntax for method calls
Speed • Source code is compiled on the fly to a bytecode format. Hence similar to Java in performance and about 10x slower than C. • Code optimizers exist. • Opcode caching to avoid reparsing and compiling.
Compilers • Originally interpreted. Several compilers now exist: • phc • Roadsend • Raven • Phalanger • Caucho Resin/Quercus • HipHop (Facebook) • php-to-scala
Resources • Free and open source libraries • Many modules for handling internet access, databases, etc.