Can't you just put them in an array? This one uses xml but you could
adapt it to $_POST variables:
class Issue
{
public $fields = array ();
public function getField ( $fieldName )
{
return array_key_exists ( $fieldName, $this->fields ) ? $this->fields
[ $fieldName ] : "";
}
public function setFields ( $xml )
{
foreach ( $xml->field as $field )
{
$this->fields [ (string) $field ['fieldname'] ] = (string) $field;
}
}
}
That any help?
PT
Tapan Shah wrote:
> Hi All,
>
> For building variables in procedural php, we can build ${"abc".$i}
>
> Can we do a similar thing for assigning values to properties of an object
>
> For eg: $obj is an instance of a Class, which has x number of variables
>
> The following things do NOT work:
>
> 1)
> while(list($key, $val) = each($_POST))
> {
> $obj->$key=$val;
> }
>
>
> 2)
> while(list($key, $val) = each($_POST))
> {
> ${"obj->".$key}=$val;
> }
>
>
> 3)
> while(list($key, $val) = each($_POST))
> {
> $obj->{$key}=$val;
> }
>
>
> Are there any alternative to this?
>
> Thanks in advance.
>
> Regards,
> Tapan