Please help me with isset Function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • christian9997

    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
  • Tom Thackrey

    #2
    Re: Please help me with isset Function


    On 15-Nov-2003, christian9997@h otmail.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

    tom (at) creative (dash) light (dot) com
    do NOT send email to jamesbutler@wil lglen.net (it's reserved for spammers)

    Comment

    • Alexander M. Turek

      #3
      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.so urceforge.net>

      The phpMyAdmin Project
      <http://www.phpmyadmin. net>

      Comment

      • Martin McNulty

        #4
        Re: Please help me with isset Function

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

        "Alexander M. Turek" <alexander.ture k@stud.uni-karlsruhe.de> schrieb im
        Newsbeitrag news:opryovygt7 2mcye9@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


        Comment

        Working...