PHP Essentials

  1. PHP (recursive acronym for PHP: Hypertext Preprocessor) is a server-side scripting language (the oppose being JavaScript). It is not a programming language because it (an app by a programming language say Java does the oppose):
    1. Runs in response to an event
    2. Performan instructions top down
    3. Has little or no user interaction
  2. PHP
    1. is NOT a compiled language
    2. is designed to work with HTML
  3. Setting Up your local playground for Windows 10 (opinionated)
    1. Install Xampp
    2. Run these commands
      $ cd c:\xampp\htdocs && mkdir learningPHP && touch index.php && subl .
    3. Write the file say:
      <!DOCTYPE html>
        <meta charset="UTF-8">
          echo "Hello Wolrd";
    4. Open Xampp and start the PHP server
    5. Open Chrome and go to “localhost/learningPHP”, and voila
    6. Or simple go to a online code playground say’s
    7. You may want to put a “php.ini” file under your project root with the below contents to enable error report for development:
      display_errors = On
      error_reporting = E_ALL

      more for error reporting of PHP on, the official docs

    8. Other commonly used troubleshooting methods are as follows
      echo $variable;        // checking on the variable's value
      print_r($array);       // checking on the array
      gettype($variable);    // checking on the variable's value's type
      var_dump($variable);   // checking on the variable's value & its type
      get_defined_vars();    // checking on the defined variables
      dubug_backtrace();     // checking on the backtrace
    9. external debugging tools: Xdebug, DBG, FirePHP
  4. An operational trail
    1. client side: browser > server side: apache
    2. apache finds the file requested, which happends to be, say index.php
    3. apache is handling index.php, and go back and forth with the database if
    4. instructed by the index.php file. The result is a (dynamic) .html file
    5. apache sends the resulting .html file back to the browser