Find or list all constants used in a PHP file

2020-04-05 08:09发布

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;
?>

标签: php constants
2条回答
贼婆χ
2楼-- · 2020-04-05 08:50

PHP has a function for every task known to mankind.

This includes the get_defined_constants() function.

查看更多
家丑人穷心不美
3楼-- · 2020-04-05 08:56

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.

查看更多
登录 后发表回答