Connecting Tech Pros Worldwide Help | Site Map

Please help me with isset Function

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 01:09 AM
christian9997
Guest
 
Posts: n/a
Default Please help me with isset Function

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

  #2  
Old July 17th, 2005, 01:09 AM
Tom Thackrey
Guest
 
Posts: n/a
Default 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)
  #3  
Old July 17th, 2005, 01:09 AM
Alexander M. Turek
Guest
 
Posts: n/a
Default 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>
  #4  
Old July 17th, 2005, 01:09 AM
Martin McNulty
Guest
 
Posts: n/a
Default 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


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.