$functionName() or call_user_func($functionName)

If you need to provide parameters stored in another variable (in the form of array), use array unpacking operator:

$function_name = 'trim';
$parameters = ['aaabbb','b'];
echo $function_name(...$parameters); // aaa

To dynamically create an object and call its method use

$class = 'DateTime';
$method = 'format';
echo (new $class)->$method('d-m-Y');

or to call a static method

$class = 'DateTime';
$static = 'createFromFormat';
$date = $class::$static('d-m-Y', '17-08-2023');
Answer from knittl on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_functions.asp
PHP Functions
Information can be passed to functions through parameters. A parameter is just like a variable. Parameters are specified after the function name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma. The following example has a function with one parameter ($fname). When the familyName() function is called, we also pass along a name, e.g.
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ php-tutorial โ€บ php-functions.php
How to Define and Call a Function in PHP - Tutorial Republic
In this tutorial you will learn how to create your own custom functions in PHP. A function is a self-contained block of code that performs a specific task. PHP has a huge collection of internal or built-in functions that you can call directly within your PHP scripts to perform a specific task, like gettype(), print_r(), var_dump, etc.
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ functions.variable-functions.php
PHP: Variable functions - Manual
Utilize wrapper functions to make use of any of these constructs as variable functions. ... <?php function foo() { echo "In foo()<br />\n"; } function bar($arg = '') { echo "In bar(); argument was '$arg'.<br />\n"; } // This is a wrapper function around echo function echoit($string) { echo $string; } $func = 'foo'; $func(); // This calls foo() $func = 'bar'; $func('test'); // This calls bar() $func = 'echoit'; $func('test'); // This calls echoit() ?>
๐ŸŒ
Reintech
reintech.io โ€บ blog โ€บ php-functions-creating-calling-and-reusing-code
PHP Functions: Creating, Calling, and Reusing Code | Reintech media
February 1, 2026 - In software development, 'Calling a PHP Function' refers to the process of activating or triggering a particular PHP function that has already been defined elsewhere in the code. This is done by using the function's name followed by parentheses, ...
๐ŸŒ
Exakat
exakat.io โ€บ home โ€บ how to call a method in php
How to call a method in PHP - Exakat
December 14, 2024 - Use the native call_user_func or call_user_func_array to call any function or method. The first parameter is the name of the function, and the same rules we have already seen apply : make the name of the function fully qualified.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ php โ€บ how-to-call-php-function-from-string-stored-in-a-variable
How to call PHP function from string stored in a Variable - GeeksforGeeks
July 11, 2025 - Given the names of some user-defined functions stored as strings in variables. The task is to call the functions using the names stored in the variables. Example: ... <?php // Function without argument function func() { echo "geek"; } // Function ...
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ php โ€บ php_functions.htm
PHP - Functions
In front of the name, put a parenthesis, which may or may not contain arguments. It is followed by a block of statements delimited by curly brackets. This function block contains the statements to be executed every time the function is called. The general syntax of defining a function is as follows โˆ’ ยท <?php function foo($arg_1, $arg_2, $arg_n) { statements; return $retval; } ?>
Find elsewhere
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ php tutorial โ€บ php call function
PHP Call Function | How to Create User-Defined Function in PHP?
March 23, 2023 - The output of the program will be the names of the employee passed in the function while calling it. 2. In the below example, the employee names are printed and also the employee ID is printed along with it. When an organization has chunks of data to be stored in the database, we can simply write this kind of code to handle the data with ease. ... <?php function Employee($ename, $id) { echo "Employee name is $ename and Employee id is $id \n"; } Employee("Lakshmi","780540"); Employee("Rohit","780541"); Employee("Jenny","780542"); ?>
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ guide to php functions with examples
Functions in PHP : Guide to PHP Functions with Examples | Simplilearn
September 10, 2025 - Know What is PHP Functions, Creating PHP Function, PHP Functions with Parameters, Setting Default Values for Function Parameters, & Dynamic Function Calls. Read Now!
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-declare-and-call-a-function-in-php
How to Declare and Call a Function in PHP
February 13, 2024 - Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.
๐ŸŒ
3D Bay
clouddevs.com โ€บ home โ€บ php guides โ€บ how to define and call functions?
How to define and call functions?
June 5, 2024 - ```php function greet() { echo "Hello, World!"; } ``` Parameters: You can specify parameters within the parentheses to allow the function to accept input values. Parameters are variables that hold the data passed into the function.
๐ŸŒ
Code.mu
code.mu โ€บ en โ€บ php โ€บ faq โ€บ how-to-call-php-function
How to Call a PHP Function
To call our function, we need to write its name and parentheses, like this: func. We can either output the function's result directly to the screen, or store it in a variable and then do something with it. Let's output the result of our function to the screen as an example: <?php function func() ...
๐ŸŒ
Envato Tuts+
code.tutsplus.com โ€บ home โ€บ coding fundamentals
How to Call a PHP Function From JavaScript | Envato Tuts+
October 29, 2021 - If you are using jQuery on your website, it becomes incredibly easy to call any PHP file with code that you want to run. You can pass one or two parameters to the ajax() function. When two parameters are passed, the first one will be the URL of the webpage where the browser will send your request.