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
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?
5. Data Types - Literals
• Literals are also known as Primitive Values
• Representative of fixed values, such as numbers or text
• 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?
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
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!
10. Pulling Files From Git (cont)
• 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