2

How do i get an request_vars from RestRequest Object..i want all the fields from an array.Below is the mentioned code

RestRequest Object
(
[request_vars:RestRequest:private] => Array
(
[{
"taskStmt":"demoo",
"description":"",
"projectId":"",
"assignedDate":"",
"endDate":"",
"TaskEffort":"",
"estimateTime":"",
"dependencies":_"",
"priority":"",
"timeTaken":"",
"workCompletion":"",
"status":"",
"user_id":"",
"mailsent":"",
"completiondate":""
}
] =>
)

[data:RestRequest:private] =>
[http_accept:RestRequest:private] => json
[method:RestRequest:private] => put
)
1
  • The array is private you need to access it via a public method Commented Sep 26, 2012 at 12:39

2 Answers 2

2

According to your dump, request_vars is a private and no-static attribute.

So you need a getter method like this:

class RestRequest
{
    // ...

    public function getRequestVars()
    {
        return $this->request_vars;
    }
}

In this way you cannot edit/write the value of request_vars directly, but you can read it through the getRequestVars() public method:

var_dump( $object->getRequestVars() );
Sign up to request clarification or add additional context in comments.

1 Comment

hey i have created RestRequest class and wrote this setter and getter but unable to retrive this data..please help?
1

Update:

The examples you posted in comment have a getRequestVars() method on the class RestRequest, that should return those values.

You can get around visibility modifiers like protected and private with Reflection if you must, but probably not a good idea:

class Foo {
    public    $foo  = 1;
    protected $bar  = 2;
    private   $baz  = 3;
}

$foo = new Foo();

$reflect = new ReflectionClass($foo);
$props   = $reflect->getProperties();

foreach ($props as $prop) {
    $prop->setAccessible(true);
    print $prop->getName().' = '.$prop->getValue($foo)."\n";
}

3 Comments

I quote you... in fact reflection is slow and in this case a bad practice.
There's a getRequestVars() method on RestRequest class in the examples, that should return what you want.
As complex857 has said, in the RestRequest class of the example you linked there is already a getRequestVars() method like the code of my answer

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.