Re: global to superglobal

From: Date: Sat, 11 Jan 2003 21:09:54 +0000
Subject: Re: global to superglobal
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-131282@lists.php.net to get a copy of this message
At 04:16 AM 1/12/2003 +0800, you wrote:
On Sunday 12 January 2003 03:45, pippo@bellnet.ca wrote: I have a database that was created on an earlier version of PostgreSQL and uses global variables with register_globals = on for php4. I have migrated the database to postgresql-7.3.1 with mod_php-4.2.3 and have set the register_globals to on. In order to use the default setting of register_globals = off, I need to reprogram my php files. I would appreciate some suggestions on how to go about modifying the code. Is there a script that could be run on each file to convert to the superglobals that would work with the register_globals off? If only it was that easy ;)
That should be: "If only it were that easy" - subjunctive, :)) sorry, it's my English studies that keep coming back at me....
The best thing to do is crank up error reporting to maximum (errors AND notices). You should see a lot of undefined or uninitialized variables notices/warnings. Find out where those variables are coming from (GET, POST or whatever) and change them appropriately. Eg you have a form with method=POST and a single text element called 'name'. Instead of using just $name in your code you need to use $_POST['name']. I also need to know the exact syntax: for example, one current line is - include "$DOCUMENT_ROOT/../lib/somefile.conf"; Someone did suggest the following: include $_SERVER['DOCUMENT_ROOT'].'/../lib/somefile.conf'; however, there is a difference in the use of the quotation marks and I do not understand the use of the . and .. It used to be that $DOCUMENT_ROOT was a predefined variable in the global scope. Thus you could use it directly in a string like in your first statement. Now DOCUMENT_ROOT can only be obtained from the $_SERVER array. Between strings and variables the period (.) acts as a concatenation operator. The second statement can be reformatted to make it clearer: $_SERVER['DOCUMENT_ROOT'] . '/../lib/somefile.conf'; Hopefully you can clearly see that the left side is equivalent to $DOCUMENT_ROOT and the right side is just a string. The '..' in the string on the right has nothing to with PHP, it's just the standard way to denote the parent directory. Single-quoted strings are literal strings, double-quoted strings does variable expansion. The second statement can also be rewritten as: "{$_SERVER['DOCUMENT_ROOT']}/../lib/somefile.conf";
Thanks, Jason. This helps somewhat. Most of the variables should be fairly obvious, I should think. So, it should not be too difficult to do some search & replace of stuff like the $_SERVER['DOCUMENT_ROOT'] stuff. I suppose I could then try to run the stuff with error reporting maxed out. Does that seem about right or should I start with the error reports and go at it one by one. Being terribly lazy, I suppose makes me want to find shortcuts. I understand laziness is also a sign of genius... :)) PJ

« previous php.general (#131282) next »