0

When I try to get the value of a boolean param, with ReflectionMethod, that have a default value set, I got empty result.

With this code:

    public function GetOrderBook($symbol = null, $limit = 100, $async = false)
    {
        if ($symbol !== null) {

            $params = [];
            $ref = new \ReflectionMethod($this, 'GetOrderBook');

            foreach ($ref->getParameters() as $param) {
                $name = $param->name;
                $params[$name] = $$name;
            }

            print_r($params);
        }
    }

I get this:

 Array ( 
      [symbol] => ETHBTC 
      [limit] => 100 
      [async] => 
 ) 

Is there a way to get the default value of a param with reflection?

1
  • [async] => means that value of async is false, because string representation of false is empty string. Use var_dump instead of print_r and you will see real values. Commented Oct 15, 2017 at 9:54

1 Answer 1

1

print_r function outputs string representation of values. String representation of false is empty string. To see real values that you have in an array, use var_dump:

var_dump($params);

After that you will see that:

["async"]=>bool(false)
Sign up to request clarification or add additional context in comments.

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.