Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    61
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Variable Declaration

    Hi,

    I have just started using PHP and I am wondering if there is a PHP equivalent of Perl's

    Code:
    use strict;
    or

    Code:
    my $var;
    It seems to me that variables are used without declaration or initialisation...

    /jlar

  • #2
    Regular Coder
    Join Date
    May 2008
    Posts
    187
    Thanks
    7
    Thanked 7 Times in 7 Posts
    That is correct, PHP is a weakly typed language. Which means you don't have to predeclare a variable, and variables do not have assigned types and can change at any time.

    edit: Personally, I don't like it, but that's how it is.

  • #3
    Regular Coder
    Join Date
    Apr 2008
    Location
    New Jersey
    Posts
    116
    Thanks
    0
    Thanked 29 Times in 29 Posts
    The best PHP can do toward acting like 'use strict' is error_reporting(E_ALL). This gets you many warnings related to variable definition and can occasionally help you catch things. It's still not nearly as good as 'use strict'.
    Chaos
    Lost Souls: text based RPG | MUDseek: MUD gaming search | MUDfind: MUD resource sites | Discordian Quotes


  •  

    Posting Permissions

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