0

Hi,

I have data like this -

Someting Object
(
    [_values:protected] => Array
        (
            [key1] => something,
            [key2] => something else,
etc...

How do i access that _values:protected part? I tried $name->_values:protected, but it gives me an error.

Thanks

4
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by diafol
0

Post the error.. Have you tried making a public function, returning then echoing the value you want?

echo $name -> functionName(); 
or
protected _values = whatever;
echo $name -> _values;
0

protected values can only be accessed by the class or any class that extends.

class foo{
	protected $value = 'test';
	
        //only this class can call privates ^_^
	private $val2 = 'hohoho';
	
	public function getVal () {
		return $this->value;
	}
}

class bar extends foo{
	
	public function getFooVal(){
		return $this->value;
	}
	
	public function getFooVal2(){
		return $this->$val2;
	}
	
}

$a = new foo();

$a->getVal(); //ok

$a->value; //nope

$b = new bar();

$b->getFooVal(); //ok

$b->getFooVal2(); //nope
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.