Skip to content

Instantly share code, notes, and snippets.

@ilya-dev
Created April 2, 2014 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilya-dev/9937057 to your computer and use it in GitHub Desktop.
Save ilya-dev/9937057 to your computer and use it in GitHub Desktop.
To prevent an accidental assignment when comparing two variables, wrap the first one within parentheses.
<?php
$foo = 10; $bar = 9;
var_dump($foo = $bar); // whoops, accidental assignment! but no message will be displayed
var_dump(($foo) = $bar); // again, but this is a syntax error b/c an expression can't have a value assigned to it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment