• Like
PHP Underground Session 1: The Basics
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

PHP Underground Session 1: The Basics



Published in Education , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Underground PHP  by Rob Hawkes i7872333@bournemouth.ac.uk
  • 2. The ground rules
  • 3. What the sessions are ✽ Somewhere to admit lack of understanding ✽ Covering areas missed in workshops ✽ Helping you understand programming theory – critical! ✽ Focussing on the “why” over “how” ✽ A launch pad for further learning
  • 4. And what they aren’t ✽ Quick fix for The Station • Will provide examples of when to use techniques in context • Will not provide code to copy & paste ✽ Easy • PHP takes time & effort to learn
  • 5. These go without saying ✽ Provide your own equipment • We might not always be in the labs • I can’t provide individual web space ✽ Don’t piss about • Please only come if you genuinely want to learn • I won’t waste my time or yours
  • 7. Session 1: The Basics
  • 8. What we’ll cover ✽ An introduction to PHP ✽ Where to get help when you’re stuck ✽ Best practice when coding ✽ Fundamental knowledge
  • 9. PHP: An introduction
  • 10. What is PHP? ✽ Stands for PHP: Hypertext Preprocessor • Yes, a recursive acronym. Funky! ✽ Run directly on the web server • Windows, Linux, and Mac ✽ Makes web pages dynamic • Calculations, database interaction, etc. ✽ Latest version is PHP 5 • Introduces features not supported in PHP 4
  • 11. Basic PHP process User's Browser Web Server (Apache) PHP Engine MySQL Database
  • 12. Where to get help
  • 13. Online help ✽ Official PHP documentation • php.net ✽ Stack Overflow • stackoverflow.com ✽ SitePoint forums • sitepoint.com/forums ✽ Google
  • 14. Offline help ✽ Don’t look at me • Would love to but I don’t have the time ✽ Books • PHP and MySQL for Dynamic Web Sites • PHP and MySQL Bible
  • 15. Best practice
  • 16. Indentation & spacing ✽ Neat & tidy ✽ Makes code readable ✽ Less prone to error ✽ Easier to debug in future
  • 17. Indentation & spacing Unindented Indented <?php <?php $array=array(‘1’,‘2’,‘3’,‘4’,‘5’); $array = array(‘1’, ‘2’, ‘3’, ‘4’, ‘5’); $count=count($array); $count = count($array); for($i=0;$i<$count;$i++){ if($i==2){ for ($i = 0; $i < $count; $i++) { echo $array[$i]; if ($i == 2) { } echo $array[$i]; } } ?> } ?>
  • 18. Unindented Indented
  • 19. Comment everything ✽ // comments a single line ✽ /* text */ comments multiple lines ✽ Helps with learning ✽ Make comments meaningful • Explain in detail exactly what the code does ✽ Saves time when debugging ✽ Will save your arse many times
  • 20. Naming conventions ✽ camelCase • Always start with a lowercase letter • Capitalise the first letter of any further words ✽ Meaningful names • ShowProfile() rather than function1() • Makes code readable at a glance
  • 21. Further reading ✽ Zend Framework coding standards • http://framework.zend.com/manual/en/coding- standard.html
  • 22. Fundamental knowledge
  • 23. General syntax ✽ Wrap all PHP within <?php and ?> tags • Tells server that the code within is to be run through the PHP system ✽ End every line with a semicolon; • Ok, not every line but enough to use that rule • Lets the PHP system know where a line of code ends • Most rookie errors are caused by forgetting semicolons
  • 24. General syntax ✽ Use $variables to store data for later • Variables are always preceded with a $ symbol • They can’t begin with a number • Any type of data can be stored inside a variable ✽ Echo and print • Used to output data to the browser • Negligible difference in performance between the two • Most programmers use echo
  • 25. Data types Name Short name Notes Boolean bool Truth value, either true or false Integer int Whole number (eg. 5) Floating point float / double Decimal fraction (eg. 1.7) String str Series of characters, usually text, enclosed in quotation marks Array arr Used to store multiple pieces of data in one place
  • 26. Assignment operators Operator Example Notes = $a = 1+4; Assigns the left operand (variable) to the value on the right += $a += 5 Adds the value on the right the existing value of $a -= $a -= 5 Subtracts the value on the right from the existing value of $a .= $a .= ‘Hello’ Appends the value on the right to the existing value of $a, mainly used with strings
  • 27. Arithmetic operators Operator Name Notes -$a Negation Opposite / reverse of $a $a + $b Addition Sum of $a and $b $a - $b Subtraction Difference of $a and $b $a * $b Multiplication Product of $a and $b $a / $b Division Quotient of $a and $b $a % $b Modulus Remainder of $a divided by $b
  • 28. Comparison operators Operator Name Notes $a == $b Equal True if $a is equal to $b $a === $b Identical True if $a is equal to $b, and are of the same data type $a != $b Not equal True if $a is not equal to $b $a !== $b Not identical True if $a is not equal to $b, or they are not of the same data type $a < $b Less than True if $a is less than $b $a > $b Greater than True if $a is greater than $b $a <= $b Less than or True if $a is less than or equal to $b equal to $a >= $b Greater than or True if $a is greater than or equal to equal to $b
  • 29. Increment & decrement Operator Name Notes ++$a Pre-increment Increase $a by one then return $a $a++ Post-increment Return $a then increase $a by one --$a Pre-decrement Decrease $a by one then return $a $a-- Post-decrement Return $a then decrease $a by one
  • 30. Logic operators Operator Name Notes $a and $b And True if both $a and $b are true $a && $b And True if both $a and $b are true $a or $b Or True if $a or $b is true $a || $b Or True if $a or $b is true $a xor $b Xor True if $a or $b is true, but not both !$a Not True if $a is not true
  • 31. Operator roundup ✽ PHP uses the same operators as most major programming languages ✽ = does not mean ‘equal to’ • = is used to assign a value • == means ‘equal to’
  • 32. Further reading ✽ PHP.net data types documentation • http://www.php.net/manual/en/ language.types.intro.php ✽ PHP.net operator documentation • http://www.php.net/manual/en/ language.operators.php ✽ PHP.net type comparison tables • http://www.php.net/manual/en/ types.comparisons.php
  • 33. Any questions?