PHP Static Class Problem

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
artofwork
Forum Newbie
Posts: 7
Joined: Wed Feb 08, 2012 1:28 am

PHP Static Class Problem

Post by artofwork »

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--;
	}
}
?>
artofwork
Forum Newbie
Posts: 7
Joined: Wed Feb 08, 2012 1:28 am

Re: PHP Static Class Problem

Post by artofwork »

Forgot to mention the problem lol... its late.. The problem is I'm trying to generate more then 1 textarea in the area, it creates the box and remove it but doesn't create more then 1.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: PHP Static Class Problem

Post by Mordred »

Did ... did you just write 30+ lines of code to do that?
*shudder*
Anyway, try ++$index. Or even better, Ctrl+A, Del
Post Reply