Categoría: Tecnología al Día
<?php function foo() { function bar() { echo «I don’t exist until foo() is called.\n»; } } /* We can’t call bar() yet since it doesn’t exist. */ foo(); /* Now we can call bar(), foo()’s processesing has made it accessible. */ bar(); ?>
<?php $makefoo = true; /* We can’t call foo() from here since it doesn’t exist yet, but we can call bar() */ bar(); if ($makefoo) { function foo() { echo «I don’t exist until program execution reaches me.\n»; } } /* Now we can safely call foo() since $makefoo evaluated to true */ if ($makefoo)
The include() statement includes and evaluates the specified file. The documentation below also applies to require(). Files are included based on the file path given or, if none is given, the include_path specified. If the file isn’t found in the include_path, include() will finally check in the calling script’s own directory and the current working
require() is identical to include() except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue. See the include() documentation for how this works.
If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. return() will also end the execution of an eval() statement or script file. If called from the global scope, then execution of the current script file is ended.
The declare construct is used to set execution directives for a block of code. The syntax of declare is similar to the syntax of other flow control constructs: declare (directive) statement The directive section allows the behavior of the declare block to be set. Currently only two directives are recognized: the ticks directive (See below
The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.
continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration. Note: Note that in PHP the switch statement is considered a looping structure for the purposes of continue. continue accepts an optional numeric argument which
break ends execution of the current for, foreach, while, do-while or switch structure. break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of. <?php $arr = array(‘one’, ‘two’, ‘three’, ‘four’, ‘stop’, ‘five’); while (list(, $val) = each($arr)) { if ($val == ‘stop’) { break; /*