PHP Static Class Problem
Posted: Wed Feb 08, 2012 1:35 am
I've been playing around with this code I wrote all day and I cannot find a solution besides using a loop and parameters to pass to this class which i'm trying to avoid, could someone take a look and tell what the heck im doing wrong. Classes are very new to me.
Code: Select all
<?php
class CreateField
{
private static $field = array();
private static $index = 0;
function __construct($_POST)
{
switch($_POST)
{
case 'add':
self::createField();
break;
case 'sub':
self::destroyField();
break;
default:
break;
}
}
private static function createField()
{
self::$field[self::addIndex()] = "<textarea name=\"text_".self::$index."\"></textarea><br />";
}
private static function destroyField()
{
self::$field[self::subIndex()] = " ";
}
public function getField()
{
return self::$field;
}
private static function addIndex()
{
return self::$index++;
}
private static function subIndex()
{
return self::$index--;
}
}
?>