Professional Documents
Culture Documents
Bill Jerome
PHP Hypertext Preprocessor
http://www.php.net/manual/en/function.strlen.
php
All string functions
Some are “obvious” to c programmers
strlen, printf, fprintf, strpos
Some are web tailored
htmlentities, htmlspecialchars
Others are new (hacky)
addcslashes, explode, soundex, quotemeta, …
Classes
OOP
Class structures will be defined, helping
integration with other apps and work together
APIs followed by implementation
Inheritance
Object serialization
“Magic functions”
Class example
class Cart
{
var $items; // Items in our shopping cart
// Add $num articles of $artnr to the cart
function add_item ($artnr, $num)
{
$this->items[$artnr] += $num;
}
// Take $num articles of $artnr out of the cart
function remove_item ($artnr, $num)
{
if ($this->items[$artnr] > $num) {
$this->items[$artnr] -= $num;
return true;
} else {
return false;
}
}
}
Inheritance example
Class ParentObject {
var $value;
function ParentObject() {
$this->value = 42;
}
}
class MemberObject extends ParentObject {
var $string;
function MemberObject() {
$this->string = "This is a test string.";
$this->ParentObject();
}
}
class ObjTest {
var $ObjPointer;
function ObjTest() {
$tmp = new MemberObject;
$this->ObjPointer = $tmp;
}
}
$object = new ObjTest;
echo "String Contents: " . $object->ObjPointer->string . "\n";
echo "Value Contents: " . $object->ObjPointer->value . "\n";
Back to being hacky…
$object = new a;
$object->b = "hello";
$member_name = 'b';
echo $object->$member_name;
$object->$member_name = " world";
echo $object->$member_name;
Resources
http://www.php.net
http://www.evilwalrus.com/
http://www.devnetwork.net/