Loading presentation...

Present Remotely

Send the link below via email or IM


Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.


PHP: From non-programmer to Zend PHP5 Certified Engineer

This prezi is part of the course "PHP, from non-programmer to Zend Certificate"

Christopher Valles

on 19 October 2010

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of PHP: From non-programmer to Zend PHP5 Certified Engineer

Lanu La LLLLL Language Basics Lexical Structure Data Types Variables Expressions and Operators Flow-Control Statements Including Code Embedding PHP in Web Pages Case sensitive Statements and Semicolons Whitespaces and Line Breaks Comments Literals Identifiers Keywords echo("hello, world");
ECHO("hello, world");
EcHo("hello, world"); echo 'Hello, world';
myfunc(23, 'Prezi');
$z = 28;
$module = 'poll';
$e = $r / 90;
if($e == $z) { echo 'Deleted!'; } if($a == $b){
echo 'We have the same number';
} statement semicolon compulsory myfunc($name, $surname, $age, $location); myfunc(
); $x = 7; //Store 7 in the variable $x Worthless comment! //convert &#nnn; entities into characters
$text = preg_replace('/&#([0-9])+;/e', "chr('\\1')", $text); useful comment Shell-style comments
# This is the comment one
C++ style comments
// This is the comment two
C style comments
/* This is the comment three */ 2001 0xFE 1.55362 "Hi John" 'Candy' TRUE NULL Variable names Function names Class names Constants $john
$_name $not valid var
$3cols valid invalid $hot_stuff
$HOT_STUFF different myfunc
_myPrivateFunction addUser
AdDuSeR The same function Person
BankAccount stdClass reserved!!! not case-sensitive Always begin with dollar sign ($)
Case-sensitive Not case-sensitive Only scalar values Boolean
String define('ITEMS_PER_PAGE', 12);
echo ITEMS_PER_PAGE; __CLASS__ Abstract Break Class else echo die function elseif exit foreach final for endfor Implements static public private Integers Floating-Point Numbers Strings Booleans Arrays Objects Resources NULL Range From -2.147.483.648 to +2.147.483.647 Decimal
Hexadecimal 1998
+43 0833
+010 0xFE2
-0xAD0E3 is_int()

//$x is an integer
} PHP Function to check if the data type is integer Range From 1.7E-308 to 1.7E+308 Formats Usual format

-8.91 Scientific Notation

17.0372E-4 Useful function if(is_float($x)){
//$x is a floating-point number
} PHP Function to check if the datatype of a variable is float Useful functions Formats 'Fat dog'
"Treat me right" Expanding strings $name = "Guido";
echo "Hi, $name\n";
echo 'Hi, $name';

Hi, Guido
Hi, $name \"
\0 through \777
\x0 through \xFF Escape sequences Double quotes
Carriage return
Dollar sign
Left brace
Right brace
Left bracket
Right bracket
ASCII character represented by octal
ASCII character represented by hex $dos_path = 'C:\\WINDOWS\\SYSTEM'; $publisher = 'Tim O\'Reilly';

echo "$dos_path $publisher\n";

C:\WINDOWS\SYSTEM Tim O'Reilly Useful functions if ($a == $b){
echo "a and b are equal"
} if (is_string($x)){
// $x is a string
} Values evaluated as false •The keyword false
•The integer 0
•The floating-point value 0.0
•The empty string ("") and the string "0"
•An array with zero elements
•An object with no values or functions
•The NULL value Examples $x = 5; // $x has a true value
$x = true; // clearer way to write it $y = ""; // $y has a false value
$y = false;// clearer way to write it Useful functions if (is_bool($x)) {
// $x is a Boolean
} Generic array Associative array $person[0] = 'Edison';
$person[1] = 'Wankel';
$person[2] = 'Crapper'; $creator['Light bulb'] = 'Edison'; $creator['Rotary Engine'] = 'Wankel'; $creator['Toilet'] = 'Crapper'; $person = array(
); $creator = array(
'Light bulb'=> 'Edison',
'Rotary Engine' => 'Wankel',
'Toilet'=> 'Crapper'
); Loop through arrays foreach ($person as $name){
echo "Hello, $name\n";

foreach ($creator as $invention => $inventor){
echo "$inventor created the $invention\n";
} Sorting arrays sort($person);
// $person is now array('Crapper', 'Edison', 'Wankel')

$creator is now:
'Toilet'=> 'Crapper',
'Light bulb'=> 'Edison',
'Rotary Engine' => 'Wankel'
*/ Useful function if (is_array($x)) {
// $x is an array
} Class Keyword class Person{
public $name = '';

function name($newname = NULL){
$this->name = $newname;
return $this->name;
} Usage $ed = new Person;
printf("Hello, %s\n", $ed->name);

$tc = new Person;
printf("Look out below %s\n", $tc->name);

Hello, Edison
Look out below Crapper Useful functions if(is_object($x)){
// $x is an object
} Example $res = database_connect(); // fictitious database connect function database_query($res);
$res = "boo"; // database connection automatically closed Useful functions if(is_resource($x)){
// $x is a resource
} Example $aleph = "beta";
$aleph = null;
$aleph = Null;
$aleph = NULL; Useful functions if(is_null($x)){
// $x is NULL
} Case-insensitive Description $name
$MAXIMUM_IMPACT $what = "Fred";
$what = 35;
$what = array(
); $day = 60 * 60 * 24;
echo "There are $day seconds in a day.\n";

There are 86400 seconds in a day. if ($uninitialized_variable === NULL){
echo "Yes!";

Yes! Variable Variables $foo = 'bar';
$$foo = 'baz';

echo ???;

baz Variable References $black =& $white; $big_long_variable_name = "PHP";
$short =& $big_long_variable_name;
$big_long_variable_name .= " rocks!";

print "\$short is $short\n";
print "Long is $big_long_variable_name\n"; $short is PHP rocks!
Long is PHP rocks! $short = "Programming $short";

print "\$short is $short\n";
print "Long is $big_long_variable_name\n"; $short is Programming PHP rocks!
Long is Programming PHP rocks! $white = "snow";
$black =& $white;


print $black;

snow Variable Scope Local Global Static function update_counter(){

$counter = 10;
update_counter( );
echo $counter; function update_counter(){
global $counter;

$counter = 10;
update_counter( );
echo $counter; function update_counter(){

$counter = 10;
update_counter( );
echo $counter; function update_counter(){
static $counter = 0;

echo "Static counter is now $counter\n";

$counter = 10;
update_counter( );
update_counter( );
echo "Global counter is $counter\n";

Static counter is now 1
Static counter is now 2
Global counter is 10 function greet($name){
echo "Hello, $name\n";


Hello, Janet Garbage Collector Copy-on-write $worker = array(

$other = $worker; // array isn't copied

$worker[1] = 36; isset / unset $s1 = isset($name); // $s1 is false
$name = "Fred";
$s2 = isset($name); // $s2 is true

$name = "Fred";unset($name); // $name is NULL
Full transcript