Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • PHP Tutorial
  • PHP Exercises
  • PHP Array
  • PHP String
  • PHP Calendar
  • PHP Filesystem
  • PHP Math
  • PHP Programs
  • PHP Array Programs
  • PHP String Programs
  • PHP Interview Questions
  • PHP GMP
  • PHP IntlChar
  • PHP Image Processing
  • PHP DsSet
  • PHP DsMap
  • PHP Formatter
  • Web Technology
Open In App
Next Article:
PHP | get_class() Function
Next article icon

PHP func_get_arg() Function

Last Updated : 09 Jul, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

The func_get_arg() function is an inbuilt function in PHP which is used to get a mentioned value from the argument passed as the parameters.

Syntax:

mixed func_get_arg( int $arg )

Parameters: This function accepts a single parameter as mentioned above and described below.

  • $arg: This parameter holds the argument offset where the offset of the arguments in the parameter is counted by assuming the first argument to be 0.

Return Value: This method returns the mentioned argument and returns FALSE if an error occurs.

Example 1:




<?php
  
// Function definition
function geeks($a, $b, $c) {
  
    // Calling func_get_arg() function  
    echo "Print second argument: "
        . func_get_arg(1) . "\n";
}
  
// Function call
geeks('hello', 'php', 'geeks');
  
?>
 
 

Output:

Print second argument: php

When does any error occur?
The error occurs in two cases.

  • If the value of argument offset is more than the actual value of arguments passed as the parameter of the function.
  • If this function is not being called from within the user-defined function.




<?php
  
// Function definition
function geeks($a, $b, $c) {
  
    // Printing the sixth argument
    // that doesn't exist
    echo "Printing the sixth argument: "
        . func_get_arg(5) . "\n";
}
  
// Function call
geeks('hello', 'php', 'geeks');
  
?>
 
 

Output:

  Warning:  func_get_arg():  Argument 5 not passed to function in       [...][...] on line 4

Example:




<?php
  
// Function definition
function geeks($a, $b, $c) {
     $a = "Bye";
}
  
// Function call
geeks('hello', 'php', 'geeks');
  
// The func_get_arg() function
// is called from outside the
// user defined function
echo "Printing the sixth argument: "
        . func_get_arg(5) . "\n";
          
?>
 
 

Output:

  PHP Warning:  func_get_arg():  Called from the global scope -   no function context in /home/main.php on line 9         

For versions before PHP 5.3: Getting a function’s argument has a different approach for the PHP versions below 5.3. All the versions above 5.3 and 5.3 will show an error for the following code.

Example:




<?php
function geeks() {
    include './testing.inc';
}
  
geeks('Welcome', 'PHP', 'Geeks');
?>
 
 

testing.inc:




<?php
  
$parameter = func_get_arg(1);
var_export($parameter);
  
?>
 
 

Output:

  'PHP' warnings  

Note: For getting more than one argument func_get_args() function can be used instead of func_get_arg() function.



Next Article
PHP | get_class() Function

G

geeksforgeeks user
Improve
Article Tags :
  • PHP
  • Web Technologies
  • PHP-function

Similar Reads

  • PHP func_get_args() Function
    The func_get_args()  is an inbuilt function in PHP that is used to get a function argument list in an array form. This function is similar to func_get_arg(). Syntax: array func_get_args()Parameters: This function does not accept any parameter. Return Value: This method returns an array, where a copy
    1 min read
  • PHP func_num_args() Function
    The func_num_args() function is an inbuilt function in PHP that returns the number of arguments in the user-defined function. Syntax: func_num_args(): intParameters: This function doesn't accept any parameter. Return Values: The number of arguments will be returned into the current user-defined func
    1 min read
  • PHP | get_class() Function
    The get_class() function is an inbuilt function in PHP which is used to return the class name of an object. Syntax: string get_class( object $object ) Parameters: This function accepts single parameter $object which holds the object that need to be tested. The value of this parameter can be omitted
    1 min read
  • PHP ob_get_clean() Function
    The ob_get_clean() function is an in-built PHP function that is used to clean or delete the current output buffer. It's also used to get the output buffering again after cleaning the buffer. The ob_get_clean() function is the combination of both ob_get_contents() and ob_end_clean(). Syntax: string|f
    2 min read
  • PHP get_defined_functions() Function
    The get_defined_functions() function is an inbuilt function in PHP which returns the all defined functions in the array format. Syntax: array get_defined_functions( bool $exclude_disabled = true )Parameters: This function accepts one parameter that is described below: $exclude_disabled: It will chec
    2 min read
  • PHP | get_called_class() Function
    The get_called_class() function is an inbuilt function in PHP which is used to get the class name where the static method is called. Syntax: string get_called_class( void ) Parameters: This method does not accept any parameter. Return Value: This function returns the class name on success and return
    1 min read
  • PHP | call_user_func() Function
    The call_user_func() is an inbuilt function in PHP which is used to call the callback given by the first parameter and passes the remaining parameters as argument. It is used to call the user-defined functions. Syntax: mixed call_user_func ( $function_name[, mixed $value1[, mixed $... ]]) Here, mixe
    2 min read
  • PHP | getcwd( ) Function
    The getcwd() function in PHP is an inbuilt function which is used to return the current working directory. This function does not accepts any parameter and returns the current working directory on successful function call or FALSE on failure. Syntax: getcwd() Parameters: This function does not accep
    1 min read
  • PHP create_function() Function
    The create_function() is an inbuilt function in PHP which is used to create an anonymous (lambda-style) function in the PHP. Syntax: string create_function ( $args, $code ) Parameters: This function accepts two parameters which is describes below: $args: It is a string type function argument. $code:
    2 min read
  • PHP array_​key_​first() Function
    The array_​key_​first() function is an inbuilt function in PHP that is used to get the first key of an array. This function returns the first key without affecting the internal array pointer. Syntax: int|string|null array_key_first(array $array) Parameters: This function accepts a single parameter $
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences