0

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?

8
  • there's no error in this code Commented Jul 2, 2012 at 13:23
  • yes it is... i actually use it often int templates instead of using a separate declaration block. Commented Jul 2, 2012 at 13:25
  • $var='Hello' was successful so you really did mysql_real_string_escape(true); (p.s. its mysql_real_escape_string) Commented Jul 2, 2012 at 13:26
  • @Waygood you mean $var == 'Hello' Commented Jul 2, 2012 at 13:28
  • @Waygood but the function not working when I do this. Commented Jul 2, 2012 at 13:28

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

3 Comments

But the function mysql_real_string_escape not working at all when I do this.
I think that the function is mysql_real_escape_string() :)
mysql_real_string_escape or mysql_real_escape_string?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.