Friday 15 June 2007

Beginning PHP and MySQL 5 - Chapters 1-7

Ch 1 - An Introduction to PHP
Basically the history of PHP and why you should use it.

Ch 2 - Installing and Configuring Apache and PHP
Useful in getting started up. There are a lot of configuration options listed out. Using default values so skipped over it for now.

Ch 3 - PHP Basics
Learned the syntax that are available, quite a few including a short form version. Went through comments, outputting to html, datatypes, variables and constants, expessions and control structures like if, if-else and switch.

Ch 4 - Functions
All about functions, the prototype for a function is similar to a method:
function function_name(parameters)
{
function-body
}
There is no return type required. If needed, it can be added to the body.

Variable functions are functions which are evaluated at execution time to retrieve their names:
$function()
Given a URL parameter, this allows one to bypass the tedious if statement in order to know which function to call:
if($trigger == "retrieveUser")
{
retrieveUser($rowid);
}
else if($trigger == "retrieveNews")
{
retrieveNews($rowid);
}
else if($trigger == "retrieveWeather")
{
retrieveWeather($rowid);
}
to the much more compact:
$trigger($rowid);
There are security risks in using this so care must be taken.

Reuseable functions can be stored in a function library and called up by:
include("function.library.php");

Ch 5 - Arrays

Of note is the natural sorting function, natsort(), which sorts (10, 1, 20, 2) to (1, 2, 10, 20) instead of (1, 10, 2, 20).

Ch 6 - Object-Oriented PHP
Normal OO stuff that can be found in C or Java. The Properties feature in PHP can be used to extend the class by adding in new properties. A potential gotcha for constructors is that they do not call the parent constructor automatically.

Ch 7 - Advanced OOP Features
Again more of the same. However there are OOP features that are not supported such constructor, method and operator overloading. There is a section on reflection, showing how to obtain the class type, methods and parameters.

No comments: