PHP Static Class Problem
Posted: Wed Feb 08, 2012 2:13 am
I've been trying to find a solution all day with this code i wrote, besides using a for loop and passing numerical values to this class which i'm trying to avoid, I guess I just don't fully understand the concept of a static class.
This class generates a textarea and removes it aswell, my goal is to generate more then 1 textarea hence why im using a class, I mean could just easily write it as a function, but its really not the point.
Was wondering if someone could have a look and tell me what the heck im doing wrong, not looking for you to write it for me, just a clear explanation of why this isn't working like I want it to.
This class generates a textarea and removes it aswell, my goal is to generate more then 1 textarea hence why im using a class, I mean could just easily write it as a function, but its really not the point.
Was wondering if someone could have a look and tell me what the heck im doing wrong, not looking for you to write it for me, just a clear explanation of why this isn't working like I want it to.
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--;
}
}
?>