0
public function addSpouse($name = ($this->data['gender'] == MALE && empty($name)) ? 'Wife' : 'Husband', $suggest = false)

PHP is following for the above line:

syntax error, unexpected '$this' (T_VARIABLE)

$this is not allowed in function parameter?

EDIT: function is inside a class

Piyush
  • 131
  • 6
  • Of course, not. `$this` is a reference to the instance of a class. What are you going to refer to, if there is no object? – abcdn Mar 05 '17 at 11:08
  • Possible duplicate of [Parse error: syntax error, unexpected (T\_VARIABLE)](http://stackoverflow.com/questions/28952930/parse-error-syntax-error-unexpected-t-variable) – Anil Mar 05 '17 at 11:11
  • addSpouse is inside a class. – Piyush Mar 05 '17 at 12:08

1 Answers1

0

You cannot use a variable ($this->data or any variable) as a default parameter value. Default function parameter values must be constants.

public function addSpouse($name = 'Wife')

is correct but not:

public function addSpouse($name = $data)
SegFault
  • 1,097
  • 1
  • 14
  • 14