Server Side Programming Articles - Page 1566 of 2650

PHP Constants

Malhar Lathkar
Updated on 19-Sep-2020 15:00:15

304 Views

IntroductionConstants are represented literally in an assignment expression such as $x=10 or $name="XYZ" where 10 and XYZ are numeric and string constants assigned to variables. In PHP, it is possible to define a constant with a user defined identifier with the help of define() functionSyntaxdefine ( string $name , mixed $value [, bool $case_insensitive = FALSE ] ) : boolparametersSr.NoParameter & Description1namename of the constant.2valuevalue of the constant may be any scalar value (integer, float, string etc) or array3case_insensitiveConstant identifiers are case sensitive by default. If this parameter is set to true, name and NAME are treated similarlyReturn ValueFunction returns ... Read More

PHP Variable functions

Malhar Lathkar
Updated on 18-Sep-2020 14:00:58

11K+ Views

IntroductionIf name of a variable has parentheses (with or without parameters in it) in front of it, PHP parser tries to find a function whose name corresponds to value of the variable and executes it. Such a function is called variable function. This feature is useful in implementing callbacks, function tables etc.Variable functions can not be built eith language constructs such as include, require, echo etc. One can find a workaround though, using function wrappers.Variable function exampleIn following example, value of a variable matches with function of name. The function is thus called by putting parentheses in front of variableExample Live ... Read More

PHP User-defined functions

Malhar Lathkar
Updated on 18-Sep-2020 13:57:22

22K+ Views

IntroductionPHP has a large number of built-in functions such as mathematical, string, date, array functions etc. It is also possible to define a function as per specific requirement. Such function is called user defined function.A function is a reusable block of statements that performs a specific task. This block is defined with function keyword and is given a name that starts with an alphabet or underscore. This function may be called from anywhere within the program any number of times.Syntax//define a function function myfunction($arg1, $arg2, ... $argn) {    statement1;    statement2;    ..    ..    return $val; } ... Read More

PHP Function arguments

Malhar Lathkar
Updated on 18-Sep-2020 13:38:56

6K+ Views

IntroductionA function in PHP can be defined to accept input from calling environment/script in the form of arguments. These arguments are given as comma separeted list inside the parentheses in front of name of function. Note that while calling a function, same number of arguments must be passed to it.PHP supports calling a function by passing value, reference, arguments with default value and by passing variable number of arguments.function with argumentsIn following example, a function is defined with two formal arguments. When this function is called by passing the arguments by value. Arguments of function become its local variables. Hence, ... Read More

PHP return Statement

Malhar Lathkar
Updated on 18-Sep-2020 13:30:52

3K+ Views

IntroductionThe purpose of return statement in PHP is to return control of program execution back to the environment from which it was called. Upon returning, execution of expression following the one which invooked other function or module.If return statement occurs inside a function, execution of current function is terminated, handing over the control back to the environment from which it was called. The return statement may have an exprssion as optional clause in front of it. In that case, value of the expression is also returned in addition to the control.If encountered in an included script, execution of current scripts ... Read More

PHP require_once Statement

Malhar Lathkar
Updated on 18-Sep-2020 13:23:49

395 Views

IntroductionThe require_once statement in PHP is similar in functioning to that of require statement. Only difference is, if a file has been already included for processing, it will not be included again.Note that a file included with either include or require statement will also be not included again even if require_once statement is used.Other behaviour of require_once statement is similar to require statement .require_once ExampleIn following example main php script includes test.phpExample Live Demo //test.php OutputThis will produce following result when main script is run from command line −inside main script now including with require_once test.php script File included try to include ... Read More

PHP require Statement

Malhar Lathkar
Updated on 18-Sep-2020 13:22:25

322 Views

IntroductionEffect of require statement is similar to include statement in PHP. However, there is one main difference. If the parser fails to find required file, it produces a fatal error thereby termination of current script. The include statement on the other hand emits a warning in case of failure to find file and execution of current script continues.PHP parser tries to locate the file in current folder by default and further in directories mentioned in include_path setting of php.ini, as in case of include statement. If file asked for is not available in current folder as well as include_path folders, ... Read More

PHP include_once Statement

Malhar Lathkar
Updated on 18-Sep-2020 13:17:27

360 Views

IntroductionJust as the include statement, include_once also transfers and evaluates script written in one file in another, the difference in two lies in the fact that include_once prevents same file from reloading if already done. As the name indicates, a file will be included only once even if one tries to issue include instruction again.The include_once statement is typically used to set up global variables, enable libraries or any such activity that is expected to be done in the beginning of execution of application.Other than this, behaviour of include_once statement is similar to include statement.include_once ExampleIn following example testscript.php is ... Read More

PHP Unsetting References

Malhar Lathkar
Updated on 18-Sep-2020 12:18:59

312 Views

IntroductionIt is possible to break binding between the content and variable by using unset() function. The unset() function doesn't destroy the content but only decouples variable from it.Example Live DemoOutputAfter unsetting, $b can be used as normal vaiablebefore unsetting : 10 10 after unsetting : 10 20Reference can also be removed by assigning variable to NULLExample Live DemoOutputResult of above script is as followsx and y are references 100 x: 200 y:

PHP Spotting References

Malhar Lathkar
Updated on 18-Sep-2020 12:17:24

249 Views

IntroductionMany syntax constructs in PHP are implemented via referencing mechanisms. If reference to a global variable is unset in a function, the same variable in global namespace is not removed.Example Live DemoOutputGlobal $va1 is intact.Hello World, Hello World Hello PHP, Hello PHP Hello PHPdebug_zval_dump() function can be used if a variable has references to other variables

Advertisements