Function Call Operations

This section describes the function call operation, which triggers the execution of the called function with arguments provided on the call.

Calling a function in PHP is simple. All you have to do is to just use the function name with an argument list in any expression:

   ... function_name(argument_1, argument_2, ...) ...

When the execution reaches this function call operation, it will:

Here is a simple example script showing us how to use function call operations:

<?php # FunctionCallOperations.php
#- Copyright (c) 2015,, All Rights Reserved.

#  Defining a function that returns a value
   function f2c($fahrenheit) {
      $celsius = ($fahrenheit - 32.0 ) / 1.8;
      return $celsius;

#  Defining a function that returns NULL
   function showAnyFooter($author) {
      print("    Copyright: $author\n");
      print("    Last Modified: 2015\n");

   print("\n Function call as a standalone expression:\n");
   showAnyFooter("Herong Yang");

   print("\n Function call as an operand of another operation:\n");
   if (f2c(20.0)<0.0) print("    It's cold here!\n");

   print("\n Function call as an argument of another call:\n");
   print("    How is the temperature? ");

If you run this sample script, you should get:

 Function call as a standalone expression:
    Copyright: Herong Yang
    Last Modified: 2015

 Function call as an operand of another operation:
    It's cold here!

 Function call as an argument of another call:
    How is the temperature? 43.3333333333

Last update: 2015.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.0

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

 Expressions, Operations and Type Conversions

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

Function Declaration, Arguments, and Return Values

 What Is a Function?

 "function" Statements - Defining Functions

Function Call Operations

 Passing Arguments to Functions

 Example of Passing Arguments by Values

 Using Pass-by-Value Arguments for References

 Example of Passing Arguments by References

 Variable-Length Argument Lists

 Providing Default Values to Argument Variables

 Returning Values from Functions

 Returning References from Functions

 Arrays - Ordered Maps

 Configuring and Sending out Emails

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Outdated Tutorials


 PDF Printing Version