1

i have this type of array:-
i want to get array elemtn.

context_course Object
 (
                     [_id:protected] => 15
                     [_contextlevel:protected] => 50
                     [_instanceid:protected] => 2 
                     [_path:protected] => /1/3/15 [_depth:protected] => 3 
)

the problem is [_id:protected]
i want to there value 15
how can i get if element is protected.
thanks.

1
  • 2
    inherit that class with a new class and there you will have an access to the protected property of the class Commented Jun 13, 2013 at 8:12

2 Answers 2

5

If a property is protected, it means the developer of the class doesn't want you to be able to freely directly access or modify its value from the public context.

If you analyze the class definition for this object, you will most likely find a method that will give you access to the value, for example it could be:

$obj->getId();

More info: Property Visibility

Sign up to request clarification or add additional context in comments.

1 Comment

What if key has a dollar sign? How do I access then....Obviously $obj->get{'$t'}(); has failed.
2

This is not an array, it is an object.

You will need to implement a public accessor, also known as a getter to access the object property.

class context_course 
{
  public function getId()
  {
    return $this->_id;
  }
}

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.