php - constructor param not available in init


I try to use one Zend_Form for update and create and want to switch both through a param. But my approach using the constructor did not work. When I debug this part the property is set correctly but in the init()-method it is null again.

Maybe I do not understand the Zend_Form approach. Can you help me? Where is the error?

Form Class:

class Application_Form_User extends Zend_Form {
    const CREATE = 'create';
    const UPDATE = 'update';

    protected $_formState;

    public function __construct($options = null, $formState = self::CREATE) {

        $this->_formState = $formState;
        $this->setAction('/user/' . $this->_formState);

    public function init() {


    if ($this->_formState == self::CREATE) {
            $password = new Zend_Form_Element_Password('password');
                    ->addFilter(new Zend_Filter_StringTrim());

Usage in controller action:

$form = new Application_Form_User();
$this->view->form = $form->render();

Thank you.




Theinit() method is called insideparent::__construct($options). Try this:

public function __construct($options = null, $formState = self::CREATE) {
    $this->_formState = $formState;

    $this->setAction('/user/' . $this->_formState);

I switched the first two lines of the constructor.

People are also looking for solutions to the problem: php - CKFinder enable file browser


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.