Sie sind auf Seite 1von 20

SYNAPSEINDIA SHARING REVIEWS

ON DEVELOPING WEB
APPLICATIONS WITH PHP PART 2

PHP LANGUAGE BASICS

Constants, Data Types and Variables


Data

types

Arrays
Perl-like syntax

$arr = array("foo" => "bar", 12 => true);

same as

$arr[foo] = bar;
$arr[12] = true;

PHP LANGUAGE BASICS

Constants, Data Types and Variables

Arrays (cont.)
<?php
$arr = array("somearray" => array(6 => 5, 13 => 9,
"a" => 42));

?>

echo $arr["somearray"][6]; // 5
echo $arr["somearray"][13]; // 9
echo $arr["somearray"]["a"]; // 42

PHP LANGUAGE BASICS

Constants, Data Types and Variables


Objects

Currently not much more advanced than than associative


arrays Using constants
Before version 5.0, objects are passed by value

Slow
Functions can not easily change object variables

PHP LANGUAGE BASICS

Constants, Data Types and Variables


Operators

Contains all of the operators like in C and Perl (even the


ternary)

Statements

if, if/elseif
Switch/case
for, while, and do/while loops
Include and require statements for code reuse

BUILT-IN FUNCTIONS

What comes In the box?


Array

Manipulator Functions

sort, merge, push, pop, slice, splice, keys, count

CCVS:

Interface to Red Hats credit system


COM functions: Interface to Windows COM objects
Date and Time Functions

getdate, mkdate, date, gettimeofday, localtime, strtotime,


time

BUILT-IN FUNCTIONS

What comes In the box?


Directory

Platform independent

Error

Functions

Handling Functions

Recover from warnings and errors

Filesystem

Functions

Access flat files


Check directory, link, and file status information
Copy, delete, and rename files

BUILT-IN FUNCTIONS

What comes In the box?


IMAP

Manipulate mail boxes via the IMAP protocol

LDAP

Functions

Works with most LDAP servers

Mail

Functions

Functions

mail($recipient, $subject, $message)

BUILT-IN FUNCTIONS

What comes In the box?


Database

Functions

dba: dbm-style abstraction layer


dBase
Frontbase
Informix
Ingres II
Interbase
mSQL

BUILT-IN FUNCTIONS

What comes In the box?


Database

Functions (cont.)

MySQL
Oracle
PostgreSQL
SQL Server

MING

Macromedia Flash

PDF

Create/manipulate PDF files dynamically

BUILT-IN FUNCTIONS

What comes In the box?


POSIX

Functions

Manipulate process information

Regular

Expression Functions

Uses POSIX regex

Semaphore

and Socket Functions

Available only on Unix

Session

Management Functions

PHP ON LINUX AND WINDOWS

Code Portability
The

obvious: dont use Unix or Windows specific


functions
Create a reusable module for file system differences,
for example:

if( PHP_OS == "Linux" )


{
$ConfigPath
= "/var/www/conf";
$DataPath = "/var/www/data";
}

PHP ON LINUX AND WINDOWS

Code Portability

if( ereg("WIN", PHP_OS) )


{
$ApachePath
= C:/Program Files/Apache
Group/Apache;
$ConfigPath
= $ApachePath/htdocs/conf";
$DataPath = "$ApachePath/htdocs/data";
}
$ConfigFile = "$ConfigPath/paperwork.conf";
$CountryList = "$DataPath/countries.txt";
$StateAbbrList
= "$DataPath/usstateabbrs.txt";
$StateNameList
= "$DataPath/usstatenames.txt";

TRICKS AND TIPS

Coding

Prototype

Separate the design of the site from the coding

Turn

repetitive code into functions

Makes for more maintainable and reusable code

Turn

your web pages first

grunt code into functions

Database access, configuration file access

TRICKS AND TIPS

Debugging
Feature:

PHP is not a strongly typed language

Variables can be created anywhere in your code

Undocumented

language

Feature: PHP is not a strongly typed

Typos in variable names will cause stuff to happen

TRICKS AND TIPS

Debugging
Use

scripts to dump form and session variables

Write scripts to dump data to discover bad or missing data

TRICKS AND TIPS

Development Tools
Color

coding editors

vim, Emacs, Visual SlickEdit

IDEs

Windows
Macromedia Dreamweaver
Allaire Homesite
Zends PHPEdit
Linux
???

PHP 5

Release Date
???

Features

Complete

objects

Objects with constructors


Abstract classes
Private, protected and abstract functions
Private, protected and constant variables
Namespaces
Exception handling with try/catch blocks

RESOURCES
PHP Downloads and Online Documentation
www.php.net
Community
www.phpbuilder.com: articles on PHP, discussion forums
www.phpresourceindex.com: over 1,000 PHP scripts
www.phpvolcano.com: PHP 5 information
Newsgroups
comp.lang.php

QUESTIONS?
Any

Questions

www.php.net

Community

www.phpbuilder.com: articles on PHP, discussion forums

Newsgroups

comp.lang.php

Das könnte Ihnen auch gefallen