Author: Awais Farooq

  • Strict Typing

    PHP is widely regarded as a weakly typed language. In PHP, you need not declare the type of a variable before assigning it any value. The PHP parser tries to cast the variables into compatible type as far as possible. For example, if one of the values passed is a string representation of a number,…

  • Variable Scope

    In PHP, the scope of a variable is the context within which it is defined and accessible to the extent in which it is accessible. Generally, a simple sequential PHP script that doesn’t have any loop or a function etc., has a single scope. Any variable declared inside the “<?php” and “?>” tag is available…

  • Type Hints

    PHP supports using “type hints” at the time of declaring variables in the function definition and properties or instance variables in a class. PHP is widely regarded as a weakly typed language. In PHP, you need not declare the type of a variable before assigning it any value. The PHP parser tries to cast the…

  • Recursive Functions

    A recursive function is such a function that calls itself until a certain condition is satisfied. In PHP, it is possible to defines a recursive function. Calculation of Factorial using Recursion The most popular example of recursion is calculation of factorial. Mathematically factorial is defined as − It can be seen that we use factorial…

  • Passing Functions

    To a function in PHP, in addition to scalar types, arrays, and objects, you can also pass a function as one of its arguments. If a function is defined to accept another function as an argument, the passed function will be invoked inside it. PHP’s standard library has certain built-in functions of this type, where…

  • Returning Values

    A PHP function can have an optional return statement as the last statement in its function body. Most of the built-in functions in PHP return a certain value. For example the strlen() function returns the length of a string. Similarly, a user defined function can also return a certain value. A function is an independent,…

  • Variable Arguments

    In PHP, it is possible to write a function capable of accepting a list of arguments with variable number of elements. To declare a variable argument list, the name of the argument is prepended by the “…” (three dots) symbol. The values passed are collected into an array with the argument’s name. To call such…

  • Named Arguments

    The feature of Named Arguments has been introduced in PHP with the version 8.0. It is an extension of the existing mechanism of passing positional arguments to a function while calling. By default, values of passed arguments are copied to the corresponding formal arguments at the same position. This feature of named arguments in PHP…

  • Default Arguments

    Like most of the languages that support imperative programming, a function in PHP may have one or more arguments that have a default value. As a result, such a function may be called without passing any value to it. If there is no value meant to be passed, the function will take its default value…

  • Call by Reference

    PHP uses the “call by value” mechanism, by default, for passing arguments to a function. If the arguments within the function are changed, the changes do not reflect outside of the function. To allow a function to modify its arguments, the “call by reference” mechanism must be used. In PHP, a reference variable acts as…