Question about PHP and type checking

Discussion in 'OT Technology' started by suprropmp, Apr 25, 2005.

  1. suprropmp

    suprropmp New Member

    Joined:
    Nov 28, 2004
    Messages:
    5,326
    Likes Received:
    0
    Location:
    Los Angeles
    I'm writing a paper comparing PHP and Perl in terms of type checking and reliability. I have the Perl part down pretty well but I would appreciate some info on PHP's type checking. Anything you guys know will help.



    Thanks :wavey:
     
  2. P07r0457

    P07r0457 New Member

    Joined:
    Sep 20, 2004
    Messages:
    28,491
    Likes Received:
    0
    Location:
    Southern Oregon
    PHP's type checking is VERY lax. It can be a pain if you don't explicitly declare variable types -- but it can also be a blessing for quick development.

    Bottom line, however, is always declare your type, and you'll not have a problem.
     
  3. suprropmp

    suprropmp New Member

    Joined:
    Nov 28, 2004
    Messages:
    5,326
    Likes Received:
    0
    Location:
    Los Angeles


    I'm guessing that PHP has dynamic type checking right? If so, how is PHP's type checking different from Perls?
     
  4. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,189
    Likes Received:
    509
    PHP and PERL are both VERY weakly typed. A variable in either language only truly has a type while it holds a value.

    In either language, I'm pretty sure you can take a declared int variable, for example, and assign a string value to it without any complaints from the interpreter.

    The only real difference I can think of is the way each language treats a variable vs. an array vs. a hash.

    PHP:
    $a is a variable.
    $a[0] is the first element in an array.
    $a['blah'] is an element in an associative array or hashtable.

    PERL:
    $a is a variable.
    @a[0] is the first element in an array.
    #a['blah'] is an element in an associative array or hashtable.
     

Share This Page