jump to navigation

Multiple Constructor in PHP January 31, 2008

Posted by ordinarywebguy in PHP, PHP 5, Programming.
5 comments

How?

See code:

class MultipleConstructor {

private $info = ”;

function __construct() {
$argv = func_get_args();
switch( func_num_args() )
{
default:
case 1:
self::__construct1($argv[0]);
break;
case 2:
self::__construct2( $argv[0], $argv[1] );
break;
}
}

function __construct1($value) {
$this->info = $value;
}

function __construct2($value, $value2) {
$this->info = $value . ” ” . $value2;
}

function get() {
return $this->info;
}
}

$a = new MultipleConstructor(‘Value 1′);
echo $a->get();

$b = new MultipleConstructor(‘Value 1′, ‘Value 2′);
echo $b->get();

Viola!!!

My First PHP 5 Class Contribution at phpclasses.org February 13, 2007

Posted by ordinarywebguy in Javascript, MySQL, OOP, PHP, PHP 5.
4 comments

Entry: MySQL Data Abstraction Layer Class and Data Manipulation Class

After getting bored working with PHP 4 and deciding to get my hands dirty with PHP 5 and its OOP capability, it got me to have the classes and example and contribute it at phpclasses.org. I would have to say that its worth messing with it as you’ve be able to define the ranges or scopes of your classes, methods and its properties. Whew! I also have to say that I missed a lot of features of PHP 5 since we’re still using PHP 4 at work. And what I did was to convert the said classes to PHP 4 to be able to ulitize it. There’s only a minor modifications to it, removed access specifiers (public, private and protected) and turn “self::” to “$this->”, “__construct” to “name of class itself” and thats it.

Anyway back to my entry, you can download it here or view demo here. I’m hoping that it’ll be approved within 12 days by phpclasses people and be able helped somebody in learning PHP 5 and OOP.