Dig1108C Lesson 2


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Dig1108C Lesson 2

  1. 1. INTRO TO SERVER-SIDE PROGRAMMING Friday, September 6, 13
  2. 2. PHP As A Language PHP can be treated as a distinct language with it’s own rules It has it’s own vocabulary - words that are familiar to the language PHP has distinct grammatical rules Syntax - rules to determine the composition of sentences Semantics - the meaning and significance of words Structure - the relationship between words Friday, September 6, 13
  3. 3. Grammar and Vocaublary Reserved Words and Keywords: if, else, ifelse; for, foreach, while, do; and, or, xor; public, private, protected Expressions: semicolon (;), curly braces ({...}) Arithmetic: addition (+), subtraction (-), multiplication(*) Comparisons: equality (==), inequalities (!=), ranges (<=) Special cases: dollar($), braces ([...]), operators (&, |, <<) User & Built-in Constants: PHP_VERSION, E_ERROR, E_WARNING, E_NOTICE, MY_CONSTANT User & Built-in Functions: shuffle(), printf(), strlen() Friday, September 6, 13
  4. 4. The PHP Manual - http://php.net/manual/en/ In your “assignments” workspace, create a file called “assignment-2.1.md” to work on your answers to the following questions: Find at least three different methods to get a random value from an array with a built-in function (Look in Array Functions) What does the built-in md5() function do? What is the default return value? What built-in functions work similarly? What is another name for “anonymous functions” in PHP and where are they in the manual? When were they added and what was the last feature added? What is the default value of the “memory_limit” setting in PHP? What value would I set to it in order to allocate ALL memory to PHP? How could I set that value and where would I find that in the manual? Friday, September 6, 13
  5. 5. Data Types - Literals Literals are also known as Primitive Values Representative of fixed values, such as numbers, text, etc Four scalar types: boolean, integer float (double) & string Two compound types: array & object Three special types: resource, NULL & callable What makes 1 different from 1.0? Friday, September 6, 13
  6. 6. Working With Variables Variables are storage locations with identifiers that contain values Variables are places to store your literals. Think of a bucket. $a_variable // This is a bucket to hold literals! $a_variable = “some value” // Now the bucket has stuff in it $a_variable = “something else” // The bucket remains, but a new string is put in it Variables in PHP are always preceded with a dollar sign ($) Variables are not very useful empty, so they are usually followed with an assignment operator Friday, September 6, 13
  7. 7. Assignment Operators An operator accepts one or more literals or variables, performs an operation on them and returns the results, like a calculator. $total = 1 // total is defined as 1 $total = $total + 1 // total is now 2 $total += 2 // total is now 4 (old total plus 2) Orders of operation and precedence still apply here! Friday, September 6, 13
  8. 8. Basic “Phrases” Variables, basic expressions and comments: $david = ‘awesome’; // not entirely true Basic assignment and arithmetic operators: $counter = 1; $counter = 2; $counter = 1 + 1; $counter += 2; Getting feedback from PHP: echo $counter; var_dump($counter); var_export($counter); Friday, September 6, 13
  9. 9. ASSIGNMENT TWO Friday, September 6, 13
  10. 10. Pulling Files From Git Open your “assignments” workspace in Cloud9 In the console, type “git remote -v” to see the repository URL for the remote named “origin” Connect the “assignments” repository from the class to yours: Go to https://github.com/vcc-dig1108/assignments Copy the repo URL to your clipboard In the Cloud9 console, type “git remote add upstream “ (with the space at the end) and paste the URL that you copied Now “git remote -v” should list “origin” and “upstream” Friday, September 6, 13
  11. 11. Pulling Files From Git (cont) To get the updated code from remote use “git fetch” (try with -h) Use “git merge” to roll that update into your local branch You should now have the updated file “homework-2.1.md” All instructions are in the assignment: Open the project that you forked earlier or fork one now Grab around 50 lines of PHP from that project that show examples of literals, variables, function calls and other colored (important) things If there is something that you don’t recognize, note it for later The goal is to practice “reading” PHP grammar for now Friday, September 6, 13