1

In my php class (symfony2 entity class) I have class variable avaliable:

protected $avaliabletags = array();

Than in constructor I am putting data into that array:

/**
     * Constructor
     */
    public function __construct()
    {
        $this->avaliabletags['zatwierdzony']['name'] = "Zatwierdzony";
        $this->avaliabletags['zatwierdzony']['role'] = "ROLE_ACCEPTTAG";
        $this->avaliabletags['zatwierdzony']['label'] = "";
        $this->avaliabletags['finalized']['name'] = "Finalized";
        $this->avaliabletags['finalized']['role'] = "ROLE_ACCEPTDOC";
        $this->avaliabletags['finalized']['label'] = "";
    }

However the above code does not seem to populate class variable.

Using print_r on $this->avaliabletags result in array()

What am i doing wrong?

3
  • 1
    Where do you call print_r? Are you sure that between constructor and call for print_r you don't clear an array? Commented Jul 5, 2015 at 8:31
  • I have searched the class file and found no other references to $avaliabletags. Nonetheless I have doubts whether __construct() is executed as putting there die(); does not result in blank page. Commented Jul 5, 2015 at 8:37
  • Show us the code where you test array value Commented Jul 5, 2015 at 8:45

1 Answer 1

2

It seems that the problem is connected with the constructor not being called.

According to the doctrine2 documentation Doctrine2 never calls __construct() method of entities. http://www.doctrine-project.org/docs/orm/2.0/en/reference/architecture.html?highlight=construct.

Therefore I change the code into:

/**
 * Baza dostepnych tagów
 */
protected $avaliabletags = array(
  "zatwierdzony" => array(
    "name" => "Zatwierdzony", 
    "role" => "ROLE_ACCEPTTAG"
  ), 
  "finalized" => array(
    "name" => "Finalized", 
    "role" => "ROLE_ACCEPTDOC"
));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.