Skip to content

Instantly share code, notes, and snippets.

@danharper
Created October 15, 2013 15:01
Show Gist options
  • Save danharper/3a409f652c9b54ad5224 to your computer and use it in GitHub Desktop.
Save danharper/3a409f652c9b54ad5224 to your computer and use it in GitHub Desktop.
<?php
$x = false or true;
// => true
var_export($x);
// => false

$y = false || true;
// => true
var_export($y);
// => true

Why?

<?php
$x = false or true;

// becomes...

($x = false) or true;

// so you're assigning `false` to `$x` then comparing `$x` to `true`, which evaluates as true.

But

<?php
$x = false || true;

// becomes...

$x = (false || true);

// so you're assigning the result of the expression to `$x`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment