SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While, I was learning and reading from my PHP Book " PHP Essentials", the author could not make me clear with some syntaxes..

    i hope you guys can..

    1). what does " isset " stands for ?

    2). what does " } " stands for ?

    3). why do we add "!" when we have to check the validation of the form field on the server side. ?


    I hope that you can make these syntaxes clear to me..

    i am extremely newbie (just began it today) so a detail explanation would be good..


    Thanks,
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  2. #2
    SitePoint Wizard creole's Avatar
    Join Date
    Oct 2000
    Location
    Nashvegas Baby!
    Posts
    7,845
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1) isset is used to check if a variable "is set".

    if (isset($http_referer)

    check to see if $http_referer has a value. If it does (or not) then it performs the action specified in the code.


    2) { and } and called Braces (or curly braces). They are used to contain blocks of PHP code.

    3) ! is the inidicator for NOT. So you could say this:

    if (! isset($http_referer)

    and it would mean "If HTTP_referrer is NOT set"

    do you see the difference?
    Adobe Certified Coldfusion MX 7 Developer
    Adobe Certified Advanced Coldfusion MX Developer
    My Blog (new) | My Family | My Freelance | My Recipes

  3. #3
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks creole..

    you were very quick and very clear..

    onething isn't clear to me yet!

    } else {

    what does this means ?
    and what do you mean by pile of code ?


    also If i have any other questions in future.. i would ask it here only in this thread?
    anybody else can also ask if they have any questions.


    Thanks,
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  4. #4
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Following up on the curly braces {}. As Creole said they create blocks of code. In procecdural progamming (the most basic form of programming - which is what the last script you posted followed) there are three types of control structures:

    1) Sequence
    This is just placing one statement after another. Each statement is ended with a ";" (semicolon). Execution procedes from one statement to the next statement and so on in a linear fashion.

    2 Conditional
    This is a section of code that will only be entered if a condition is true. The code that is to be entered conditionally is seperated from the sequential code using the curly braces {}. For example:
    PHP Code:
    $string1 "This is sequential code. This statement gets executed first.";
    $string2 "Still sequential code. This statement gets exectuted second";
    if ( isset(
    $string1) )
    {
       echo 
    "This statement will only be executed if the condition above is true";

    else
    {
       echo 
    "and this statement will only be executed if the if condition is false;

    3 Iteration
    Iteration is when we want to repeat a block of code over and over until some condition is met. The condition can be placed at the begining of the block of code (evaluate the condition then enter the block of code if it is true) or at the end (enter the block of code once, then test the condition to decide whether to repeat again). Eg:
    PHP Code:
    $i 0;
    while( 
    $i 10 )
    {
       echo 
    $i ' ';
       
    $i++; // short hand way of saying $i = $i + 1

    This will output 0 1 2 3 4 5 6 7 8 9
    That is, the while condition will be evaluated. If it is true, the code in the curly brackets will be entered and executed. At the end of the code block execution will go back to the while condition which will be tested again. If it is still true, execution will loop through the while "loop" one more time, etc, etc, until the whil condition evaluates to false.

    Hope that is of benefit. Curly braces are also used in structured programming and object oriented programming to define scope. However, you probably are not interested in that at this stage - that will come later

  5. #5
    SitePoint Wizard johnn's Avatar
    Join Date
    Mar 2001
    Location
    Southern California, USA
    Posts
    1,181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will have many similar questions. Download the php manual from www.php.net and search for the unknowns.

  6. #6
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have a newbie question about isset

    what is the differnece between doing

    if isset($blah) ...

    or just

    if ($blah)

    i can't see the difference?

  7. #7
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ya exactly,

    i want to ask the same question..
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  8. #8
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    isset($var) means the variable has been declared but doesn't mean ity has a value. if ($var) means the var has a value. Take these simple examples

    PHP Code:
    $dude "Freddy";
    print (isset(
    $dude)) ? "Its set" "Its not set";
    print 
    "<br>";
    print (
    $dude) ? "It has value" "It has no value";

    //output
    Its set
    It has value


    $dude 
    "";
    print (isset(
    $dude)) ? "Its set" "Its not set";
    print 
    "<br>";
    print (
    $dude) ? "It has value" "It has no value";

    //output
    Its set
    It has no value 

    I hope that clears it up.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  9. #9
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's some more information. The following are all essentially the same :

    if ($foo)
    if ($foo != 0)
    if ($foo == true)
    if (!empty($foo))

    as if we have : $foo = 0; or $foo = false; then the above if checks will fail, the code within will not be evaluated. Now :

    if (isset($foo))

    if $foo = 0 or $foo = "" it's still considered set so the above isset if check will pass, the code within will be evaluated. 0 and false are essentially the same but the above case is a cause for confusion. Through time it'll make sense.

    Now if error_reporting has setting E_NOTICE on, if ($foo) will give a 'undefined variable' WARNING if $foo is not set, so keep that in mind, I don't ever do if($foo) for that reason, and use empty or isset or whatever.

    So, try this :

    $a = 'foo';
    if ($a == true) { echo '$a is true'; }

    It will evaluate to true, and print. Does that make sense? true and false are constants, see :

    http://www.php.net/manual/en/language.constants.php

  10. #10
    SitePoint Guru
    Join Date
    Dec 2000
    Location
    Karachi, Pakistan
    Posts
    913
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thankyou philip..

    you make it clear to me more than ever.


    thanks again all..

    if i would have any other questions.. i would surely post a reply here..


    i am also referring to the php manual so it also make things more clear.. but when I don't understand what the manual stands for.. then only i post something over here..


    thanks,
    36Host.com - $36/year web hosting [affiliates earn 30%]
    * Affordable Small Business Web Hosting since 2003! *
    "500mb space, 10gb bandwith, 50 pop/ftp accounts, php,
    mysql, pre-installed php scripts, 24/7 support & more...."



  11. #11
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that is all interesting, thanks everyone!

    one question. I often store some binary variables for say permissions so someone either has a 0 or 1 permission. Till now i have been doing

    if $random_permission { etc

    }

    sort of thing because $random_permission is either 0 or 1. That error reporting thing you mentioned, is this going to cause a problem here or will it only give the error is nothing. (which makes more sense).

    I guess i have a bit of script changing to do

  12. #12
    SitePoint Enthusiast
    Join Date
    Mar 2001
    Location
    Washington State
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how do you write :

    if $random_permission { etc

    }

    exactly?

  13. #13
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Philip Olson
    how do you write :

    if $random_permission { etc

    }

    exactly?
    looking throug my code in fact i have not really done this yet mainly because i have not done my permissions section. The only time i have really done things like this are:

    if ($action == "")

    to display a form that is then meant to be inputed

    or on very simple variable check such as

    if (!$email)

    so that i know they have not put anything in the email box at all. I think it is the if (!$email i should change).

    but which is better in this case

    if ($email = "") {

    or

    if (!(isset($email)))

    (obviously not using $email in the script before this point.

  14. #14
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    p.s. the value of

    empty("0")

    is dependant upon whether you are using php3 or php4

    http://www.php.net/manual/en/x52662.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •