Parse error: syntax error, Unexpected ''

Asked

Viewed 3,180 times

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 you’re making me wrong again:

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

  • On which line is this error? (nothing appears after the in?)

  • $msg = ("$this->user $this->password $oneclick['card']['cardNumber'] $oneclick['card']['holderName'] $oneclick['card']['expirationDate']"); echo ('Logged in - '.$msg);

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

2 answers

9

You cannot place complex expressions within strings. Prefer to concatenate from string:

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

I put in the Github for future reference.

It seems to produce a bad text to be read but at least it will work. If there are no other errors we cannot detect.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.