Share
Embed
Transcript
19 slides
-
Girl Develop It! Austin PHP/MySQL Class Session 1 Instructor: Kassandra
Perch November 2011 Session -
Introduce Yourselves! Name Occupation/Company What do you like to do
other than code? What do you want to learn? -
Course Format Session 1: Introduction to PHP Session 2: Introduction
to MySQL Session 3: Mixing PHP/MySQL Session 4: Real-World PHP/MySQL, and where to go form this course -
Class Format (Today) Introduction to PHP Course Website/Tools/Materials What is
PHP? Basic Structures/Syntax PHP Web Forms Lab/Homework -
Course Website/Tools/ Materials http:/ /www.kassandraperch.com/girldevelopit/ index.html If you have any
questions outside of class, contact me at [email protected] -
Variables Just like variables in math- they represent a range
of values over time, and an unknown or designated value at any one time. In PHP, they start with a $ You do not have to give you variables a type in PHP $hello = “Hello!” basic types include integers, floats, booleans, and strings. -
Naming Your Variables You can start variable names in PHP
with letters, numbers, or _. These are also valid characters in any part of the name General Tip: Use descriptive names over short names If your variable name has more than one word, use $camelCase or $the_underscore_technique. -
Operators Again, like in math, these manipulate values standards :
+ - * / modulus: % - returns the remainder of left argument divided by the right concatenation : . “adds” two strings See example1-1.php to see them in action -
Operators Cont. Compare: <= <, > >=, == unary operators
pre/post, --, ++ see effects in example 1-1 +=, -=, *=, /= perform operation with value and right side of = ($x += 2, $x = $x + 2). -
Some PHP Code [from example1-2.php] ...<body> <h1>My website!</h1> <?php $a
= 4; $b = 2; $c = “I have ”; $d = “ apples!”; echo $c . ($a + $b) . $d); ?> </body>... -
If statements In english: If I have more than six
apples, I will give you two. Otherwise, you will give me one. [see example1-3.php] if ( $my_apples > 6 ){ $my_apples -= 2 $your_apples += 2 } else { $my_apples += 1; $your_apples -= 1; } -
For/While Loops For: takes a value (part 1) and iterates
until that value meets a condition (part 2), doing something to that value each iteration (part 3). for( $i = 0; $i < 10; $i++){ ... } While: Iterates until a condition is met. while( $i < 10 ){ ... } See example1-4.php -
Functions functions take a block of code and execute it
when called, optionally on arguments passed to it. They can also optionally return a value. See example1-5.php function addTwoValues($val1, $val2){ $result = $val1 + $val2; return $result; } -
Objects Objects are a complex data type, comprised of attributes
and methods- attributes are either primitive data types or other objects, and methods are functions. Functions that act on that particular instance of the object are instance methods. Functions that act separate of the object are static methods. See example1-6.php -
Why we’re going into unit testing Unit testing is an
important practice Headaches of finding a bug can be large and numerous without testing The best time to pick up the habit is when you are learning to code -
What is unit testing? Short answer: A unit test is
a piece of code that runs your code and asserts facts about the answer. If the assertions are true, the test passes. If they are false, the test fails. We’re going to go through example1- tests.php for examples/explanation -
Today’s Lab: Let’s create an object Pick an object that
interests you, and let’s write the code for it Try to pick something with both attributes and methods Use Source Control! Don’t forget to write unit tests for your methods There is an example in example1-Lab.php -
Wrap-Up/HW Learned a lot about PHP today Types, operators, comparators,
functions, objects, and unit tests! Homework: Finish Lab 1, Look over the slides for session 2.