RE: [PHP-WEBMASTER] Information
| From: | Donnell, Jason | Date: | Wed, 22 Jun 2011 20:23:32 +0000 |
| Subject: | RE: [PHP-WEBMASTER] Information | ||
| References: | 1 2 | Groups: | php.webmaster |
| Request: | Send a blank email to php-webmaster+get-11255@lists.php.net to get a copy of this message | ||
-----Original Message-----
From: parasane@gmail.com [mailto:parasane@gmail.com] On Behalf Of Daniel P. Brown
Sent: Wednesday, June 22, 2011 4:13 PM
To: Donnell, Jason
Cc: php-webmaster@lists.php.net
Subject: Re: [PHP-WEBMASTER] Information
On Wed, Jun 22, 2011 at 15:48, Donnell, Jason <Jason.Donnell@fmcti.com> wrote:
> Hello,
>
>
>
> I recently resolved an issue that I was having with a server side
> script. It is a rather simple resolution, but can cause hours of
> frustration and some additional comments added to the manual might be
> extremely advantageous to other developers. I apologize in advance if
> the manual does state this, however I have triple checked the online PHP
> manual and I cannot find any information on exactly what I am going to
> describe.
>
>
>
> The manual does describe how to pass variables from JavaScript to PHP
> server side script and to different PHP functions. There is one
> important short note that is worth mentioning - Variables obtained using
> the $_Get method shall be passed to other functions by reference only.
> My theory is that since the variable is linked to the URL, and we all
> know that the URL is not changing unless you navigate to another page,
> then the variable cannot change either which means it shall be passed by
> reference only. I have found, through experience that the variable
> becomes "undefined" if it is passed by value to a function from the main
> PHP script.
>
>
>
> Here is an example of what I am saying:
>
>
>
> $id = $_get['ID']; //obtained from JavaScript
>
> .....
>
> Foo($id); //call function
>
>
>
> Function Foo($id) //invalid, id now is 'undefined'
>
> {
>
> }
>
> Function Foo(&$id) //valid
>
> {
>
> }
Part of the problems you're experiencing - unless it's a mere typo
- may be due to the fact that you've referenced both $_Get in
speaking, and $_get in your code example. Unless you've defined this
array yourself, it does not exist --- the PHP superglobal used for
storing HTTP GET data is $_GET. It is cAsE-sEnSiTiVe, as are all
variables.
--
</Daniel P. Brown>
Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting
(866-) 725-4321
http://www.parasane.net/
Yes, I am using $_GET (the PHP superglobal). That was a typo and I just did not use the correct
case when typing this email. I am able to pass variables from PHP to my PHP server script using
$_GET. It's just that once I pass the variable to the function, the variable suddenly becomes
'undefined'. I know this is strange, but the only way I could fix this problem was to
pass the variable by reference. I don't need to pass all variables by reference, just the ones
that I obtained via the $_GET function I must pass by reference.
-Jason