Re: redefine a define ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Can you just switch the order?

Instead of...

   define("SOME_CONSTANT","Generic Value");
   define("SOME_CONSTANT","Override Value");

Why not do...

   define("SOME_CONSTANT","Override Value");
   if(!defined("SOME_CONSTANT")) { define("SOME_CONSTANT","Generic Value"); }

This should avoid any redefinition and thus the notices.

Matt

On Sat, Aug 25, 2012 at 3:07 PM, Matijn Woudt <tijnema@xxxxxxxxx> wrote:
> Op 25 aug. 2012 21:03 schreef "Adam Richardson" <simpleshot@xxxxxxxxx> het
> volgende:
>>
>> On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine <lester@xxxxxxxxxxx> wrote:
>> > What I was not expecting was a string of 'Notices:' complaining about
> the
>> > redefines. So how does one get around this message? One can't 'if
> defined'
>> > as the string needs to be replaced with the more appropriate one. I
> would
>> > say, why is this even a problem, or alternatively I just give up on
> E_STRICT
>> > and make sure it's disabled again on PHP5.4?
>> >
>> > Having spent several months getting the code clean on E_STRICT,
> switching it
>> > off again will really pig me off, but I can't see any real alternative
> given
>> > the number of languages and strings that will need reworking simply to
> get
>> > things clean :(
>>
>> Well, I'd do the following to avoid issues in the future.
>>
>> 1) Create a function like that below, which provides global access to
>> variables and allows you to update existing values:
>>
>>         function val($name, $value = null)
>>         {
>>                 static $values = array();
>>
>>                 if ($value === null) {
>>                         return isset($values[$name]) ? $values[$name] :
> null;
>>                 } else {
>>                         return $values[$name];
>>                 }
>>          }
>>
>> 2) Create a php script that searches out define("SOME_NAME_PATTERN",
>> "value") and replaces that with val("some_name_pattern", "value").
>>
>> 3) Create a php script that searches out SOME_NAME_PATTERN and
>> replaces with val("SOME_NAME_PATTERN");
>>
>> Not too bad in terms of work, as PHP's parsing capabilities are really
> nice.
>>
>> Hope this gives you ideas :)
>>
>> Adam
>>
>
> That's probably quite some work given the many defines.. Fact is, constants
> are, as the name says, constant. Would it be possible to just not include
> the general file?
> Second, though not 100% sure if it works for E_STRICT is using @ before all
> defines to silence the warning. You could do a simple replace for that..
>
> - Matijn

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux