PHP Learning (functions)

Source: Internet
Author: User

A mutable function, which is called by the value of a variable, because the value of the variable is variable, so you can invoke different functions by changing the value of a variable .

Often used in callback functions, function lists, or depending on dynamic parameters to invoke different functions. The variable function is called by the variable name in parentheses.

A mutable function can also be used on an object's method call:

Here: Theobject member access symbol

When we create custom functions and understand the use of mutable functions, in order to ensure that the functions called by the program are present, we often use function_exists to determine whether a function exists. The same method_exists can be used to detect whether a class's methods exist.

class defines whether the class_exists can be used.

Parameters of the function

The argument list allows you to pass information to a function, which is a comma-delimited list of expressions. Parameters are evaluated from left to right.

PHP supports passing parameters by value (default), passing parameters by reference, and default parameters. Variable-length parameter lists are also supported.

By default, a function parameter is passed by value ( so that it does not change the value outside the function even if the value of the parameter is changed inside the function ). if you want to allow a function to modify its parameter values, you must pass the arguments by reference .

If you want a parameter of a function to always be passed by reference, you can precede the argument with a symbolic & in the function definition:

Pass by value:

Reference delivery:

The value of the default parameter

Output:

PHP Learning (functions)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.