Connecting Tech Pros Worldwide Forums | Help | Site Map

Please help me with isset Function

christian9997
Guest
 
Posts: n/a
#1: Jul 17 '05
Hi

I don't seem to understand the way isset works.

Here is some Javascript code that makes a call using PHP:

// USER CAME BACK TO CHANGE LANGUAGE
if (<?echo isset($_REQUEST["changeLanguage"])?>) {
alert("WORKS1");
desiredLanguage = "<?echo $_REQUEST["changeLanguage"]?>";
cookieIsSet = 2;
}

I am not passing any $_REQUEST["changeLanguage"] parameter!
Here is the resulting HTML page source:

// USER CAME BACK TO CHANGE LANGUAGE
if () {
alert("WORKS1");
desiredLanguage = "";
cookieIsSet = 2;
}

I thought isset should return false as it doesn't exist. Why is it
returning nothing?
Thank you for any help

Tom Thackrey
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Please help me with isset Function



On 15-Nov-2003, christian9997@hotmail.com (christian9997) wrote:
[color=blue]
> I don't seem to understand the way isset works.
>
> Here is some Javascript code that makes a call using PHP:
>
> // USER CAME BACK TO CHANGE LANGUAGE
> if (<?echo isset($_REQUEST["changeLanguage"])?>) {
> alert("WORKS1");
> desiredLanguage = "<?echo $_REQUEST["changeLanguage"]?>";
> cookieIsSet = 2;
> }
>
> I am not passing any $_REQUEST["changeLanguage"] parameter!
> Here is the resulting HTML page source:
>
> // USER CAME BACK TO CHANGE LANGUAGE
> if () {
> alert("WORKS1");
> desiredLanguage = "";
> cookieIsSet = 2;
> }
>
> I thought isset should return false as it doesn't exist. Why is it
> returning nothing?[/color]

I guess it's returning null which is evaluates to false. You could add zero
to the result or use <? echo (isset(...))?'1':'0'; ?>

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to jamesbutler@willglen.net (it's reserved for spammers)
Alexander M. Turek
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Please help me with isset Function


Hi,

Am 15 Nov 2003 08:44:47 -0800 hat christian9997
<christian9997@hotmail.com> geschrieben:
[color=blue]
>
> I thought isset should return false as it doesn't exist. Why is it
> returning nothing?
> Thank you for any help[/color]

isset() does return the boolean false, but echo needs a string, not a
boolean.
This is why php converts the boolean return value to a string, false
becomes "" (empty string).

btw, your JS does not make much sense: Why do you print an if expression
that will never be executed? Instead, you could include the JS code only
when it's needed.

--

Alexander M. Turek
<rabus@users.sourceforge.net>

The phpMyAdmin Project
<http://www.phpmyadmin.net>
Martin McNulty
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Please help me with isset Function


Thank you to both of you for your answers they were very helpful.

"Alexander M. Turek" <alexander.turek@stud.uni-karlsruhe.de> schrieb im
Newsbeitrag news:opryovygt72mcye9@news.rz.uni-karlsruhe.de...[color=blue]
> btw, your JS does not make much sense: Why do you print an if expression
> that will never be executed? Instead, you could include the JS code only
> when it's needed.[/color]

At the moment I am working on a sort of prototype using mostly HTML and
Javascript and only PHP when I really need it (for requests and database
access). Once I get the website working I will try and refine the code using
PHP.
As this is my first PHP project I'm not really sure of the impact PHP has on
the server performance, thats why I'm doing most of the processing on the
client side. However your observation is totally right and I hadn't actually
thought of it ;-)
Thanks


Closed Thread