Php Chapter 1 Training
Upcoming SlideShare
Loading in...5
×
 

Php Chapter 1 Training

on

  • 4,694 views

PHP ZEND Certification Training

PHP ZEND Certification Training
Chapter 1 Fundamentals

Statistics

Views

Total Views
4,694
Views on SlideShare
4,683
Embed Views
11

Actions

Likes
4
Downloads
97
Comments
1

6 Embeds 11

http://www.linkedin.com 5
https://www.linkedin.com 2
http://cviserver.ddns.comp.nus.edu.sg 1
http://www.slideshare.net 1
http://webcache.googleusercontent.com 1
http://kcomm.comp.nus.edu.sg 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • IT Pathshala, Noida-Sector-63, offers Guaranteed JOB with PHP Training Programs.

    PAY US ONLY IF YOU GET A JOB!

    CALL US - +91-9871350999 or +91-8800394970

    Technology Centre Address: H-110, Sector-63, Noida (UP)

    Program Takeaways:

    - GUARANTEED JOB in your technology domain
    - Live Major Project development
    - Experience Letter on Training Completion
    - Certification on Training Completion
    - Project Source Code available in CD

    Program Highlights:

    - 100% Guaranteed Job – Don’t pay us if you don’t get a JOB!
    - Industry Ready Courses
    - LIVE International Project Experience
    - Exposure to corporate culture at our IT services facility
    - Networking & Interaction with Industry Experts
    - Training Provided by a reputed IT Company
    - Live Project Source Code made available in CD
    - Technology certification and experience letter at program completion
    - Online Study Content

    CALL US - +91-9871350999 or +91-8800394970

    Our website: www.itpathshala.com
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Php Chapter 1 Training Php Chapter 1 Training Presentation Transcript

  • PHP Basics Orlando PHP Meetup Zend Certification Training January 2008
  • Anatomy of a Web Request
    • What happens when you request index.php?
    • Web server (Apache) loads handler, php application and provides URL and POST data, if any.
    • PHP:
      • Parse page to split code from html
      • Compile code
      • Execute code
      • Merges code output with html
      • Stream back to Apache, which forwards to the users browser.
  • PHP Syntax
    • Tags (Must be matched pairs)
      • <?php code ?> - Recommended
      • <? ?> - Frequently used, <?= ?> (auto echo)
      • <% %>, <script language=“php”> </script>
    • Whitespace
      • Inside script tags: Ignored
        • Just don’t break any <?php tags or function names.
      • Outside script tags: Sent to output stream exactly
    • Case Sensitive
      • $This != $this != $THIS
  • Comments
    • // Single line comment - Preferred
    • # Single line comment – Valid but deprecated
    • /* Multi-line comment */
    • /** * API Documentation Example * * @param string $bar */ function foo($bar) { }
  • Variables
    • All variables start with dollar sign: $
      • $scalar – Holds a single value
      • $array[$index] – Single element of an array
      • $object->method() – Object and method
      • $object->property – Object and property
    • Variable variables: $$variablename
      • $variablename = ‘size’;
      • $$variablename == $size
      • (Use sparingly, can drive mortal programmers insane)
  • Language Constructs
    • Code Blocks – Wrapped in {}
        • { // Some comments f(); // a function call }
    • Statements terminated with semicolon.
      • Single or multiline:
        • echo(‘this is printed’ . ‘on a single ‘ . ‘line.’);
  • Data Types
    • Scalar Types
      • boolean - A value that can only either be false (value == 0 or value = ‘’ or value ==‘0’) or true (any other value)
      • int - A signed numeric integer value
        • Decimal: 1234567890
        • Octal: 01234567 (Leading zero)
        • Hex: 0x1234567890ABCDEF
      • float - A signed floating-point value
        • Decimal: 12345.6789
        • Exponential: 123.45e67 or 123.45E67
      • string - A collection of character or binary data
  • Data Types (2)
    • Compound Types
      • Array – An ordered hash of key => value pairs
        • Key evaluates to integer or string
        • Value may be any data type.
      • Object – Containers of data and code.
    • Special Types
      • Resource – Handle to a file, database or connection
      • NULL – A special value for an uninitialized variable
  • Data Type Conversion
    • Loosely typed
      • A single variable can contain different types over it’s lifespan
    • Mostly transparent, but can be forced
      • $var = (int) (‘123’ + ‘456’) == 123456
      • $var = (int) ‘123’ + ‘456’ == 579 (Early bind)
      • Cannot convert TO a resource or class.
    • When converting to a boolean:
      • false == 0, ‘0’, ‘’, null, unset()
      • true == (! false) (Caution: ’00’ or ‘ ‘ == true)
  • Variable Naming
    • Must start with a dollar sign: $
    • Then a character (a-zA-z) or underscore
    • May contain numbers (not first character)
      • Except variable variables
        • $var = ‘123’
        • $$var = ‘value’
        • echo ${‘123’}; //outputs ‘value’
    • No punctuation or special characters
      • Valid: $value, $value123, $_val
      • Not Valid: $1value, $value.two, $value@home
  • Variable Scope
    • Function
      • Defined when first referenced (var) or assigned to.
      • Not inherited from the call stack.
      • Disposed when function exits
    • Global
      • Defined outside a function
      • Inherit into a function with global() or $GLOBALS[‘varname’]
      • Limit use to improve maintainability
    • Class
      • Class properties are visible within the class via $this->varname
  • Constants
    • define(‘CONSTANT’, ‘scalarvalue’);
    • echo CONSTANT; //No $ or single quote
    • Immutable, scopeless, ONLY scalar values (int, float, boolean, string)
  • Operators 1
    • Assignment Operators
      • assigning data to variables ($a = 1; $b = $c = 2;)
      • Value: $b = $a Reference: $b = &$a; (makes copy)
    • Arithmetic Operators
      • performing basic math functions ($a = $b + $c;)
    • String Operators
      • joining two or more strings ($a = ‘abc’ . ‘def’;)
    • Comparison Operators
      • comparing two pieces of data ($boolean = $a or $b;)
    • Logical Operators
      • performing logical operations on Boolean values
  • Operators 2
    • Bitwise Operators
      • Manipulating bits using boolean math ($a = 2 & 4;)
    • Error Control Operators
      • Suppressing errors ($handle = @fopen();)
    • Execution Operators
      • Executing system commands ($a = `ls –la`;)
    • Incrementing/Decrementing Operators
      • Inc. and dec. numerical values ($a += 1; $a++; ++$a;)
    • Type Operators
      • Identifying Objects
  • Operator Precedence & Associativity instanceof non-associative , left or left xor left and left = += -= *= /= .= %= &= |= ˆ= <<= >>= right ? : left || left && left | left * left & left == != === !== non-associative < <= > >= non-associative << >> left + - . left * / % left ! Right ˜ - (int) (float) (string) (array) (object) @ non-associative ++ - non-associative [ left Operator Associativity
  • Control Structures
    • If – Then – Else
      • if (expression1) { // True expressions } elseif (expression2) { // Optional space between else and if } else { // Nothing else matches }
      • ($a == $b) ? $truevalue : $falsevalue;
  • Switch statement
    • Does not need to evaluate on each comparison
      • $a = 0; switch ($a) { // In this case, $a is the expression case true: // Compare to true // Evaluates to false break; case 0: // Compare to 0 // Evaluates to true break; default: // Will only be executed if no other conditions are met break; }
  • Iteration Constructs
    • While (pre-comparison)
      • $i = 0; while ($i < 10) { echo $i . PHP_EOL; $i++; }
    • Do (post comparison)
      • $i = 0; do { echo $i . PHP_EOL; $i++; } while ($i < 10);
  • for() and foreach()
    • for(init ; compare ; increment) {}
      • for ($i = 0; $i < 10;$i++) { echo $i . PHP_EOL; }
    • foreach ($array as $element)
      • $arr = array (‘one’, ‘two’, ‘three’); foreach ($arr as $item){ echo $item . PHP_EOL; }
    • foreach ($assoc_array as $key => $item)
      • $arr = array (‘one’ => ‘uno’, ‘two’ => ‘dos’); foreach ($arr as $english => $spanish) { echo “$english means $spanish ”; }
  • Breaking Out: break [n]
    • Exits the current loop ( for, foreach, while, do-while or switch but NOT if) and optionally parents
    • $i = 0; while (true) { if ($i == 10) { break; } echo $i . PHP_EOL; $i++; }
    • for ($i = 0; $i < 10; $i++) { for ($j = 0; $j < 3; $j++) { if (($j + $i) % 5 == 0) { break 2; // Exit from this loop and the next one. } } } //break continues here
  • Continue
    • Skips rest of loop and restarts
      • for ($i = 0; $i < 10; $i++) { if ($i > 3 && $i < 6) { continue; } echo $i . PHP_EOL; }
      • Can also take an optional parameter to restart optional parents.
  • Errors and Error Management
    • Types of errors:
      • Compile-time errors
        • Errors detected by the parser while it is compiling a script. Cannot be trapped from within the script itself.
      • Fatal errors
        • Errors that halt the execution of a script. Cannot be trapped.
      • Recoverable errors
        • Errors that represent significant failures, but can still be handled in a safe way.
      • Warnings
        • Recoverable errors that indicate a run-time fault. Do not halt the execution of the script.
      • Notices
        • Indicate that an error condition occurred, but is not necessarily significant. Do not halt the execution of the script.
  • Error Reporting
    • Set via INI configurations
      • error_reporting=E_ALL & ~E_NOTICE
      • From code: error_reporting(E_ALL & ~E_NOTICE)
      • display_errors = on #Show in browser
      • log_errors = on # Write to log file or web server log
  • Handling Errors
    • Global error handling function
      • $oldErrorHandler = ’’; //Stores name of old function function myErrorHandler($errNo, $errStr, $errFile, $errLine, $errContext) { global $oldErrorHandler; logToFile(&quot;Error $errStr in $errFile at line $errLine&quot;); // Call the old error handler if ($oldErrorHandler) { $oldErrorHandler ($errNo, $errStr, $errFile, $errLine, $errContext); } } //Set up a new error handler function, returns the old handler function name $oldErrorHandler = set_error_handler(’myErrorHandler’);
    • Ignore & Check
      • $return = @function_call($params); //Internal only if ($return === FALSE) { //Handle Error }
  • Summary
    • Language fundamentals are building blocks of programming.
      • Build a strong foundation and your architecture will follow.
      • Be clear, concise and always explain why when writing code.
      • Pick a standard and stick with it.
      • Don’t be afraid to read and reread the documentation
        • http://www.php.net/manual/
  • Homework
    • Write the classic “Hello World” application.
      • Build an index.php that prints out “Hello [[name]]” 5 times in the middle of a page.
      • Page needs to be fully formed html, <html> through </html>.
      • [[Name]] should be collected from the $_REQUEST[‘name’] variable.
      • If the [[name]] is less than 5 characters, it should be in all capitals. Otherwise, print it out as received.