Конструктор PHP с параметром

Мне нужна функция, которая будет делать что-то вроде этого:

$arr = array(); // this is array where im storing data

$f = new MyRecord(); // I have __constructor in class Field() that sets some default values
$f->{'fid'} = 1;
$f->{'fvalue-string'} = $_POST['data'];
$arr[] = $f;

$f = new Field();
$f->{'fid'} = 2;
$f->{'fvalue-int'} = $_POST['data2'];
$arr[] = $f;

Когда я пишу что-то вроде этого:

$f = new Field(1, 'fvalue-string', $_POST['data-string'], $arr);
$f = new Field(2, 'fvalue-int', $_POST['data-integer'], $arr);

// description of parameters that i want to use: 
// 1 - always integer, unique (fid property of MyRecord class)
// 'fvalue-int' - name of field/property in MyRecord class where next parameter will go
// 3. Data for field specified in previous parameter
// 4. Array where should class go

Я не знаю, как создать параметризованный конструктор в PHP.

Теперь я использую такой конструктор:

class MyRecord
{
    function __construct() {
        $default = new stdClass();
        $default->{'fvalue-string'} = '';
        $default->{'fvalue-int'} = 0;
        $default->{'fvalue-float'} = 0;
        $default->{'fvalue-image'} = ' ';
        $default->{'fvalue-datetime'} = 0;
        $default->{'fvalue-boolean'} = false;

        $this = $default;
    }
}
48
задан Kamil 18 February 2012 в 17:56
поделиться