Hi folks
I'm planning on writing a guide to hidden functionality within php; the features, functions and code which are not immediately obvious from code examples or in the manual.
These are, by definition, things i am only just stumbling upon, and so I need your help to make the list more definitive.
I currently have;
The Ternary Operator
echo (isset($name)) ? "Name is set" : "Name is not set";
I didn't find this for ages - it's not on the [man]if[/man] page, and not obvious on the comparison operators page, unless you scroll to the bottom.
Type Casting/Juggling
$number = (int) "13";
Some might argue that you don't need to type cast variables, as php automatigally juggles between them - but i'm convinced that one day i will, and besides - it's good practice.
FILE and LINE
error_log("[__FILE__][__LINE__]");
Simply put, global variables that store the current file and line being parsed. Useful in error logging.
apache_note
apache_note('session_id', session_id());
Allows getting/setting of variables between the different phases of an apache GET request. For instance, allows php to pass variables (such as the session id) to the logging module, so you can track sessions in your apache logs.
"here doc" echo syntax
echo <<<END
Here is a block of code, which can contain $variables to be parsed.
END;
Not quite sure where this comes from, guess it's an old perl survivor or something. Useful for outputting large amounts of text.
Pre- and post-increments
$counter = 5;
echo $counter++; // outputs 5
$counter = 5;
echo ++$counter; // outputs 6
If you put the ++ before the variable, the variable is incremented and then echoed. If you put the ++ after, the variable will not change until after the echo.
Anyway, that's where i'm up to at the moment - and there must be loads more. I hope this snares your curiosity; your homework is to go out there and find more examples. Oh, needless to say i'll make every effort to credit replies in the final article.
Cheers, Adam
Edited to add a few i forgot!