0
. . . .

  public $counts_per_page = 15;

  public function getNames($user_id, $count = $this->counts_per_page){
    //do stuff
  }

. . . .

I am getting an error on second parameter as it doesnt allow me to do this...

Parse error: syntax error, unexpected T_VARIABLE in

how can i solve this?Thanks in advance.

1 Answer 1

2

From the php manual:

The default value must be a constant expression, not (for example) a variable, a class member or a function call.

http://php.net/manual/en/functions.arguments.php

You can set it to null or some other default instead and then check for that within the function.

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.