Parse error: syntax error, unexpected ''

4

I want to print the value on the screen after the PHP result.

public function iniciar()
{
    $msg = '';
    $oneclick = null;
    # login...
    $this->login();

    if ($this->logado()) {
        $oneclick = $this->pegar_oneclick();


        $msg  ="$this->usuario $this->senha $oneclick['card']['cardNumber'] $oneclick['card']['holderName'] $oneclick['card']['expirationDate'] ");
        echo ('Logado - '.$msg);
    } else {
        $msg  = "$this->usuario:$this->senha";
         echo ('Não logado - '.$msg);
    }
}
}

But it is returning the error:

  

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE),   expecting identifier (T_STRING) or variable (T_VARIABLE) or number   (T_NUM_STRING) in

    
asked by anonymous 16.02.2015 / 16:31

2 answers

9

You can not put complex expressions inside strings . Prefer to concatenate string :

$msg = $this->usuario . " " . $this->senha . " " . $oneclick['card']['cardNumber'] .
    " " . $oneclick['card']['holderName'] . " " . $oneclick['card']['expirationDate'];

It seems to produce a bad text to read but at least will work. If you have no other errors we can not detect.

    
16.02.2015 / 16:38
7

Another solution is to specify the variables

$msg  ="{$this->usuario} {$this->senha} {$oneclick['card']['cardNumber']} {$oneclick['card']['holderName']} {$oneclick['card']['expirationDate']} ";
//tava sobrando um ) no fim da string
    
16.02.2015 / 16:43