1

I'm having an issue that seems like it shouldn't be an issue....I actually feel silly for not knowing this but I'm chalking it up to looking at the same code for way too long now...

I'm declaring some standard variables in my OOP class that should help me save a little space in other variables but I'm getting a T_VARIABLE error. Is there a different way I could do this? Thanks!

private $default_struc = array(
    "attributes" => array(
        "label" => "",
        "id" => "",
        "title" => "",
        "class" => "",
        "required" => "",
        "rel" => ""
    ), #end attributes
    "properties" => array(
        "disabled" => false
    ) #end properties 
);
private $input_struc = array(
    $this -> default_struc
);

2 Answers 2

1

Your problem is here:

private $input_struc = array(
    $this -> default_struc
);

You can just assign a direct value, not a value stored in another var or returned from a function/method, or concatenated,... Take a look at the php docs, there you will find a lot examples, where you can see, what's working or not

You can implement a getter method for this. Below is an example how it could look like:

// if you are using this only IN the class, you can keep it private
private function getInputStruc() {
    return array_merge(
        $this->default_struc,
        array(
            /*something*/
        )
    );
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the info. I read up the docs and since I've never tried to implement this before, I wasn't aware of it. I fixed it though with a little help from my construct. Thanks again!
1

So after reading up on the PHP docs, I solved the problem. I don't know if it's the best solution but here it is in case it helps anyone else.

private $default_struc = array(
    "attributes" => array(
        "label" => "",
        "id" => "",
        "title" => "",
        "class" => "",
        "required" => "",
        "rel" => ""
    ), #end attributes
    "properties" => array(
        "disabled" => false
    ) #end properties 
);
private $input_struc = array();

Since it's a class, I used my __construct to make it how I wanted.

function __construct($title, $action = "", $name = "", $rel = ""){
    $this -> input_struc = array_merge($this -> default_struc, $this -> input_struc);
        $this -> input_struc['attributes']['type'] = "";
        $this -> input_struc['attributes']['value'] = "";

1 Comment

glad that you found a solution :)

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.