Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse error: syntax error, unexpected '"' when I use 'class' on php

Tags:

php

class

class MailAuthGen{
    var $mail='[email protected]';
    var $findUid = "SELECT uid from 'accounts' where email='$mail'";
    function abc() {
        echo $this->findUid;
    }
}

when I load this page, the page shows

Parse error: syntax error, unexpected '"'

Even

$findUid = "SELECT uid from 'accounts' where email='".$mail."'";

didn't work.

But, when I didn't use 'class', it executed well.

What's the problem?

like image 916
Hoon Avatar asked Mar 04 '26 06:03

Hoon


1 Answers

The error is with this line. You can't evaluate any variables when declaring properties.

var $findUid = "SELECT uid from 'accounts' where email='$mail'";
//                              You can't do this ------^

A common workaround is something like:

var $findUid = "SELECT uid from 'accounts' where email='%s'";

Where you can interpolate the value later.

like image 119
Mike B Avatar answered Mar 06 '26 21:03

Mike B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!