Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find or list all constants used in a PHP file

Tags:

php

constants

How to manage constants?

I am using zencart for my site.

I add all global constants in:

includes/languages/english/english.php

and my contants use in any of my pages, such as:

includes/modules/meta_tags.php

The problem is that some days I delete a constant from any php file, but I dont remove it in english.php.
Time after time, I dont know what constants in english.php are in use and where are they used.

Is there any way to know what constants are used in a php file?

<?php 
    // includes/languages/english/english.php
    define('HELLO','hello');
    define('WORLD','world');
?>

<?php 
    // includes/modules/meta_tags.php
    echo HELLO;
?>

<?php 
    // includes/modules/product_listing.php
    echo WORLD;
?>
like image 559
mingfish_004 Avatar asked Jul 03 '13 02:07

mingfish_004


2 Answers

PHP has a function for every task known to mankind.

This includes the get_defined_constants() function.

like image 118
alex Avatar answered Nov 10 '22 02:11

alex


some ides, like netbeans, phpstorm, and probably many others have features like "find usages" and "refactor" which are really useful when renaming/updating/deleting, and they support constants.

this doesn't tell you "what comments are used in a specific file", but, i'm guessing its useful to you for similar purposes.

like image 28
goat Avatar answered Nov 10 '22 02:11

goat