itsme
itsme

Reputation: 575

PHP not triggering an error

I just did a syntax like this

mysql_real_escape_string($var = 'Hello');
print_r($var);

and I got the echo of Hello, so I wondering is that syntax legal in PHP? if not why doesn't PHP trigger an error that is not legal?

Upvotes: 0

Views: 63

Answers (1)

Pekka
Pekka

Reputation: 449385

mysql_real_string_escape($var = 'Hello');

That's legal, although it won't do what you want.

Hello is assigned to $var and then the value is used as an argument to call the function.

However, $var will not be escaped this way! The return value of mysql_real_escape_string() will be lost.

So don't do this. The right way to do it would be

$var = "Hello";
$var_escaped = mysql_real_escape_string($var);

print_r($var_escaped);

Upvotes: 3

Related Questions