6

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;
?>
1
  • An editor like PHPStorm has the capability to help you follow where variables are declared, set, and read. However I don't think it can even deduce constants, but it does have project wide file search for which you can search for 'HELLO' etc Commented Jul 3, 2013 at 2:20

2 Answers 2

3

PHP has a function for every task known to mankind.

This includes the get_defined_constants() function.

Sign up to request clarification or add additional context in comments.

1 Comment

PHP's greatest strength and greatest weakness :p
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.