Skip to content

Functions

IT Notes → PHP @ December 22, 2020

  • There is no function overloading in PHP rather it may be simulated using __Call__ magic method. This is because PHP functions can take variable-length argument lists. The functions func_num_args( ), func_get_arg( ) and func_get_args( ) help us in this case.
  • PHP also provides default parameters.
  • $GLOBALS References all variables available in global scope. Use global keyword to access a global variable in a function by importing specific global variable into the local variable table.
  • Variable variables $$var.
  • Super Globals : $GLOBALS, $_GET, $_POST, $_SESSION, $_COOKIE, $_FILE, $_REQUEST $_SERVER, $_ENV.
  • While passing arguments by reference &. Similarly returning also using ampersand operator.
  • Anonymous functions or closures are given below. Anonymous functions yield objects o closure class.
  • $area=function ($side) {
    return $area * $area;
    }
    
    echo $area (5);
  • define(“constantname”, value, t/f) where true means case insensitive.
  • To check a constant, we use defined(“constantname”).
  • To return retrieve value of a constant from a variable holder or a function   we use constant($var) where $var = constantname etc.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x