Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • 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
  • 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_defined_constants() Function
Next article icon

PHP get_defined_constants() Function

Last Updated : 28 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The get_defined_constants() function is an inbuilt function in PHP that returns the name of all the constants that are currently defined with their values in the form of an associative array.

Syntax:

get_defined_constants(bool $categorize = false): array

Parameter: This function accepts single parameter that is described below:

  • $categorize: This function returns a multidimensional array that contains categories in the keys for the first dimension & constants with their values will be in the second dimension.

Return Value: This function returns an array in the form of keys and values, i.e, key name => value.

Example 1: In the below example, we will be called the get_defined_constants() function and print the associative array. Here, the get_defined_constants prints all constant as well as user-defined constants.

PHP
<?php define("MY_FIRST_CONSTANT",1); print_r(get_defined_constants(true)) ; ?> 

Output:

Array (      [Core] => Array          (             [E_ERROR] => 1             [E_RECOVERABLE_ERROR] => 4096             [E_WARNING] => 2             [E_PARSE] => 4             [E_NOTICE] => 8             [E_STRICT] => 2048             [E_DEPRECATED] => 8192             [E_CORE_ERROR] => 16             [E_CORE_WARNING] => 32             [E_COMPILE_ERROR] => 64             [E_COMPILE_WARNING] => 128             [E_USER_ERROR] => 256             [E_USER_WARNING] => 512             [E_USER_NOTICE] => 1024             [E_USER_DEPRECATED] => 16384             [E_ALL] => 32767             [DEBUG_BACKTRACE_PROVIDE_OBJECT] => 1             [DEBUG_BACKTRACE_IGNORE_ARGS] => 2          )     [user] => Array         (             [MY_FIRST_CONSTANT] => 1         )  )

Example 2: In the below example, we will print only user define constant user get_defined_constants() function.

PHP
<?php define("MY_FIRST_CONSTANT",1); print_r(get_defined_constants(true)["user"]) ; ?> 

Output:

Array  (     [MY_FIRST_CONSTANT] => 1  )

Reference: https://www.php.net/manual/en/function.get-defined-constants.php


Next Article
PHP get_defined_constants() Function

N

neeraj3304
Improve
Article Tags :
  • PHP
  • PHP-function

Similar Reads

    PHP Defining Constants
    In a production-level code, it is very important to keep the information as either variables or constants rather than using them explicitly. A PHP constant is nothing but an identifier for a simple value that tends not to change over time(such as the domain name of a website eg. www.geeksforgeeks.or
    2 min read
    PHP constant() Function
    The constant() function returns the value of a constant. It also works with class constants. Syntax: constant(constant) Parameter Values: constant: It is a required value that specifies the value of the constant. Return Value: It returns the value of a constant if the constant is defined else return
    1 min read
    PHP | get_defined_vars() Function
    The get_defined_vars() function is an inbuilt function in PHP which is used to returns an array of all defined variables. This function returns a multidimensional array which contains all the list of variables, environment etc. Syntax: array get_defined_vars( void ) Parameters: This function does no
    1 min read
    PHP | defined() function
    The PHP defined() function is an inbuilt function in PHP which checks whether a constant is exists or not, in other words, defined or not. Syntax: bool defined($constant_name); Parameter: This function accepts a single parameter as mentioned above and described below. $constant_name: This is require
    1 min read
    PHP define() Function
    The define() function is basically used by programmers to create constant. Constants in PHP are very similar to variables and the only difference between both are the values of constants can not be changed once it is set in a program. define() returns a Boolean value. It will return TRUE on success
    2 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