Skip to content

Instantly share code, notes, and snippets.

@ilya-dev ilya-dev/tips1.php
Created Apr 2, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.