Came across this code:
<?php
require_once 'HTTP/Session/Container/DB.php';
$s = new HTTP_Session_Container_DB('mysql://user:password@localhost/db');
ini_get('session.auto_start') or session_start(); //HERE. ??
?>
What does this kind of express mean in PHP? [ a OR b] ?
ini_get('session.auto_start') or session_start();
Thanks.
That expression relies upon the way the
orworks. It’s usually used to check if either one of two booleans are true:The cool thing is that if the left part of the
oris true, it never checks the latter part because it doesn’t need to. That means that you can put an expression on each side of theor. If the left part results in a negative value (a value that resolves tofalse) then the right part will be executed. If the left part results in a positive value, one that resolves to true, then the right part will never be executed.So to summarize, this:
is identical to this:
since
ini_get('session.auto_start')results in either0or1, which evaluates tofalseandtruerespectively.