The following code is doing my head in... can someone tell me how this is evaluated...
( ! is_dir($app_path) and is_dir(DOCROOT.$app_path)) and $app_path = DOCROOT.$app_path;
Surly this can't be right, if it is it's bloody complex...
This looks like old code from the index.php.
The idea here was that you could specify your app_path relative to the website docroot, instead of a fully qualified path. By default, it is defined relative.
Thank WanWizard...
It was taken form: fuel/public/index.php but I still can't fathom its structure...
It looks like a conditional assignment but the last 'and' confuses me... the assignment is always done?
I sorted expected this or something similar...
$app_path = ( !is_dir($app_path) and is_dir(DOCROOT.$app_path)) ? $app_path = DOCROOT.$app_path : $app_path;
PS, I found the newer version on git, best check to see all the files are up to date...
It is indeed an old version, new one is here: https://github.com/fuel/fuel/blob/1.1/master/public/index.php
It's pretty simple: the right side of any logical "and" statement is only executed when the left side evaluated to true. Otherwise the right side is ignored because it doesn't matter anymore (left side false? "and" can't succed anymore thus won't be ran).
Thus if the $app_path isn't a path to a directory AND DOCROOT.$app_path is a directory, only when those 2 are true is the last part executed. Thus the assignment only happens when the left side evaluated to true. If $app_path was a valid directory the is_dir(DOCROOT.$app_path) isn't run either in that case. If $app_path isn't and DOCROOT.$app_path isn't the assignment still won't happen (left of AND already false, no reason to check the right side). Only when the first conditions evaluated to true will the parser move right and run the assignment.
Makes complete sense now... mind you using $result = (!$x and $y) ? $y : $x; is easier to understand...
Here's another one...
defined('FUEL_START_TIME') or define('FUEL_START_TIME', microtime(true));
In this instance if the left evaluates to true the right side is ignored?
I would have expected something like...
if (!defined('FUEL_START_TIME') define('FUEL_START_TIME', microtime(true));
Looks like there are a few things have to get use to... still prefer !$var as opposed to ! $var
We have some set coding guidelines among which are no single line if-statements, that all parentheses are on a line of their own and that exclemation marks get spaces on both sides.
The and/or syntax is shorthand-if that is still in line with these standards, it takes a bit getting used to but once you get it it's actually pretty intuitive. Those should always remain very simple though, the example from the old front controller is a bad one as this shorthand should only be used for single condition statements. Any complex conditions should be real if-statements.