Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

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.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

PHP: From non-programmer to Zend PHP5 Certified Engineer

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

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(
$name,
$surname,
$age,
$location
); $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
$head_title
$footerCopy
$CRAZY_VAR
$_name $not valid var
$|
$3cols valid invalid $hot_stuff
$Hot_stuff
$hot_Stuff
$HOT_STUFF different myfunc
extract_names
extraPowerLimit
UGLY_FUNCTION
_myPrivateFunction addUser
AddUser
ADDUSER
AdDuSeR The same function Person
account
BankAccount stdClass reserved!!! not case-sensitive Always begin with dollar sign ($)
Case-sensitive Not case-sensitive Only scalar values Boolean
Integer
Double
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
Octal
Hexadecimal 1998
-732
+43 0833
+010 0xFE2
0x12
-0xAD0E3 is_int()

if(is_int($x)){
//$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

3.14
0.011
-8.91 Scientific Notation

0.314E1
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 \"
\n
\r
\t
\\
\$
\{
\}
\[
\]
\0 through \777
\x0 through \xFF Escape sequences Double quotes
Newline
Carriage return
TabBackslash
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(
'Edison',
'Wankel',
'Crapper'
); $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')

asort($creator);
/*
$creator is now:
array(
'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){
if(!is_null($newname)){
$this->name = $newname;
return $this->name;
}
}
} Usage $ed = new Person;
$ed->name('Edison');
printf("Hello, %s\n", $ed->name);

$tc = new Person;
$tc->name('Crapper');
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
$Age
$_debugging
$MAXIMUM_IMPACT $what = "Fred";
$what = 35;
$what = array(
'Fred',
'35',
'Wilma'
); $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;

unset($white);

print $black;

snow Variable Scope Local Global Static function update_counter(){
$counter++;
}

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

$counter = 10;
update_counter( );
echo $counter; function update_counter(){
$GLOBALS[counter]++;
}

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

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";
}

greet("Janet");

Hello, Janet Garbage Collector Copy-on-write $worker = array(
"Fred",
35,
"Wilma"
);

$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