Welcome Guest, Not a member yet? Register   Sign In
Access server values in class variable definitions
#1

[eluser]coldscooter[/eluser]
Is there a reason I can't do this?:

class newClass extends MY_controller{

private $data = array(
'doc_root' => $this>-input->server('DOCUMENT_ROOT')'
);

}

How would i access the server variables?
#2

[eluser]Matt S.[/eluser]
Class properties can only be set with values, not variables or expressions. For what you want to accomplish, you would need to set the values of the $data array inside your constructor, like so:

Code:
class Foo extends MY_Controller {

    private $data;

    public function __construct()
    {
        $this->data = array('doc_root' => $_SERVER['DOCUMENT_ROOT']);
    }

}




Theme © iAndrew 2016 - Forum software by © MyBB