Re: [PHP] redefine a define ...
Ashley Sheridan wrote: I think the point is that the code is relying on overriding the constants, so that wouldn't help at all. I think the best thing would be to re-write the code, constants are never meant to be treated like that, it's entirely the opposite of what a constant is. I've 45 languages and several hundred strings per language ;) Redefining 'define' as a new function is looking the easiest option as I can just replace all the defines in the language files. Then simply run a clean set of defines as I can't easily replace all of that text in the rest of the code tree :( I can see why the approach was taken originally as it READS a lot better than building the translations as an array of strings which is used in other packages. There are only some 800 strings to be reworked later ... across a few hundred files ... -- Lester Caine - G8HFL - Contact - http://lsces.co.uk/wiki/?page=contact L.S.Caine Electronic Services - http://lsces.co.uk EnquirySolve - http://enquirysolve.com/ Model Engineers Digital Workshop - http://medw.co.uk Rainbow Digital Media - http://rainbowdigitalmedia.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] redefine a define ...
On Sat, 2012-08-25 at 15:17 -0400, Matt Neimeyer wrote: > 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 wrote: > > Op 25 aug. 2012 21:03 schreef "Adam Richardson" het > > volgende: > >> > >> On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine 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 > I think the point is that the code is relying on overriding the constants, so that wouldn't help at all. I think the best thing would be to re-write the code, constants are never meant to be treated like that, it's entirely the opposite of what a constant is. -- Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] redefine a define ...
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 wrote: > Op 25 aug. 2012 21:03 schreef "Adam Richardson" het > volgende: >> >> On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine 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
Re: [PHP] redefine a define ...
Op 25 aug. 2012 21:03 schreef "Adam Richardson" het volgende: > > On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine 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
Re: [PHP] redefine a define ...
On Sat, Aug 25, 2012 at 2:27 PM, Lester Caine 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 -- Nephtali: A simple, flexible, fast, and security-focused PHP framework http://nephtaliproject.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php