How to Use PHP Calls
The PHP programming language is an object-oriented language that deals with the interaction between objects. An object is an instance of a class, which is a collection of functions and data. To access a function, you make what is known as a function call. PHP allows you to call functions in several different ways. You will need to know how to make function calls if you plan on using PHP. Function calls are a very important aspect of programming.
Instructions
-
-
1
Decide how you will run your PHP code. If you have a PHP server, you can execute code using PHP files. If you do not have access to a PHP server, you can use an online PHP interpreter. Enter the code in this tutorial into either a PHP file or the online PHP interpreter.
-
2
Begin your PHP program with the following statement:
<?php
-
-
3
Create a function named 'functionName' that takes a variable as an argument and prints out that variables value. You can accomplish this by writing the following statement:
function functionName($args) { printf("%s\n",$args);
-
4
Create a variable named 'a' by writing the following statement:
$a = "Hello World"
-
5
Call the function 'functionName' directly by invoking its name and supplying it an argument, like this:
functionName($a);
-
6
Call the function 'functionName' using an alternate method. This alternate method uses the function 'call_user_func.' Pass 'call_user_func' two arguments: the name of the function you want to call, and the arguments for that function.
call_user_func('functionName', $a);
-
7
Conclude your PHP program with the statement below. Your program is now ready to be tested on your PHP server or online PHP interpreter.
?>
-
8
Run the program. The function 'functionName' is called twice, which produces the following output:
Hello World
Hello World
-
1