Question

I'm trying to (in a parallel fashion, that's it, as we're still developing under PHP 5.2.x for our main applications) adapt our current applications to PHP 5.4.x (using Apache 2.4.2 with PHP 5.4.1 in our testing server) but I'm finding some warnings in our current applications when we run them in the testing server.

For example... we're using constant definition in our current applications with a function that detects the language and loads a language file containing the definitions like idiomas/lang.php, being lang a 2-digit language representation (es, us, de, and so on).

Inside each language file there's some definitions like this one:

define("IDIOMA_AF", "Afrikaans");
define("IDIOMA_AR", "العربية");
define("IDIOMA_BG", "български език");

So, when we want to output a given translated text, we do this:

<?php echo IDIOMA_AF; ?>

The message PHP 5.4.1 outputs when the application is thrown at it is the following:

Notice: Constant IDIOMA_AF already defined in D:\apache\htdocs\aplicacion\modulos\base\idiomas\es.php on line 34

Does anyone have the same problem? I would like to know a bit about your experiences, as it would be useful to know how to solve these problems. We're thinking on implementing a better system using gettext (which I think is more organized and easier to handle in the long run, but still...), although we would like to run our current applications for a while before upgrading them.

Was it helpful?

Solution

It means you are trying to define the constant twice (which is not allowed).

You could try:

if (!defined('IDIOMA_AF')) define('IDIOMA_AF', 'Afrikaans');

Or trace, and fix, why you are defining a constant twice anyway.

The function get_defined_constants() is also a useful debugging tool for issues like these.

Or, just ignore those errors: error_reporting(E_ALL & ~E_NOTICE);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top