This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Variable Scope Example #1: | |
* | |
* $temp = preceding text. | |
* notice DECLARED var name $temp and var passed into somedate() don't have to match | |
* but RETURNED var name and passed var must match | |
**/ | |
$temp = "Ex. #1: The date is "; // set outside function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Static variables keep their value after function calls. | |
* useful for making counters to track number of function calls. | |
* bc $count has already been declared, initialization is skipped. | |
* it retains previous value, then is incremented and is displayed w new value. | |
* | |
* can only be assigned w predetermined value. | |
* cannot assign the result of an expression. | |
*/ | |
function test() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Loads of useful info here: https://www.php.net/reserved.variables.server | |
* | |
* Double check: always sanitize superglobals before using. | |
* | |
* ex. $came_from = htmlentitles( $_SERVER[ 'HTTP_REFERER' ] ); | |
* ex. echo "My username is " . $_ENV[ 'USER' ]; | |
* | |
* lists all server keys and values | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bank_balance( $checking_balance ) { | |
$savings_balance = 100; | |
if ( $checking_balance < 100 ) { | |
$money = 1000; | |
$checking_balance += $money; | |
} else { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Control structures: switch | |
* | |
* O'Reilly book: useful when on $var or result of expression can have multiple values. | |
* | |
* intersting examples in user notes | |
* https://www.php.net/manual/en/control-structures.switch.php | |
*/ | |
// $foo = "is not set"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* O'Reilly p.82 Expressions and Control Flow | |
* evaluates expression and | |
* executes two stmts: one when expression is T and one when F | |
* | |
* 1st stmt: when expression is true | |
* 2nd stmt: when expression if false | |
*/ | |
$fuel = 1.00000000000001; | |
echo $fuel <= 1 ? "<p>Better stop for gas</p>" : "<p>Keep driving</p>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* O'Reilly p.87 | |
* while vs. for loop: | |
* use while when condition DOES NOT depend on a simple, regular change to a var. | |
* use while: when checking for SPECIAL INPUT OR ERROR and end loop when it occurs. | |
*/ | |
$count2 = 0; | |
while ( $count2++ <= 12) { | |
echo "<p>$count2 times 12 is " . $count2 * 12 . "</p>"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Add detailed debug settings | |
define( 'WP_DEBUG', true ); //Turn on the debug engine | |
define( 'WP_DISABLE_FATAL_ERROR_HANDLER', true ); // Deactivate new WSOD protection | |
define( 'WP_DEBUG_LOG', true ); // error_log() will write to wp-content/debug.log | |
define( 'WP_DEBUG_DISPLAY', false ); // Write notices/warnings/errors to debug.log instead of the html | |
define( 'SCRIPT_DEBUG', true ); // Force WP to use dev/unminified versions of core CSS/JS | |
@ini_set( 'display_errors', 0 ); //Do not print error messages to screen. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display HTML classes for elements | |
* | |
* @since 0.1 | |
* | |
* @package wphierarchy | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Adds HTML markup. | |
* | |
* @package wphierarchy | |
* | |
* @since 0.1 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. |
OlderNewer