// archives

php

This tag is associated with 7 posts

A PHP Factory Pattern Example

Recently I was challenged on the fly to come up with an example of a factory pattern. Here is the result:

/**
* Database Connection Example
* @author randymelder
*/
interface DatabaseConnection {
function connect();
}
class MySQLDatabaseConnection implements DatabaseConnection {
var $link;
var $user;
var [...]

PHP Linked List Example

Continuing my data structures thoughts from previous posts, I’ve created a linked list example.

/*
* Node - a basic link node.
*/
class Node {
var $id;
var $next;
/*
*
*/
function __construct($id)
{
$this->id = $id;
}
}
$a = new Node(”mark”);
var_dump($a);
$b = $a->next = new Node(”wes”);
var_dump($b);
$c = $a->next->next = new Node(”mj”);
var_dump($c);
$d = $a->next->next->next = new Node(”bruce”);
var_dump($d);
$d->next = $b;
var_dump($d);

echo ” //loop [...]

PHP Stack - An implementation of a basic data structure

Recently, I started re-learning c++ and the topic of data structures surfaced. The conversation evolved to their usefulness in web development. Without commenting on that, I decided to partake in an exercise to implement c style functionality in a PHP OOP context. Here is the code I came up with:

/*
* Stack - the [...]

 

March 2010
S M T W T F S
« Feb    
 123456
78910111213
14151617181920
21222324252627
28293031  
  • Print this article!
  • Digg
  • del.icio.us
  • Facebook
  • TwitThis