Menu
I have seen e.g. code <?php echo @$_GET[‘index’]; ?>
what actually means @ in such cases?
in that case, it does nothing and shouldn't be used in that way.[/QUOTE]Rubbish! In this instance it is being used to suppress an E_ALL level notice. Instead of writing out
[code=php]<?php echo (!empty($_GET['index'])) ? $_GET['index'] : null; ?>[/code]
although most [I]experts[/I] think it should not be used.[code=php]<?php
error_reporting(E_ALL);
@($str .= 'foo'); // $str is not defined and would result in an error
$foo .= 'bar'; // outputs an error
?>[/code]
...[/QUOTE]The following is from
[CODE]no warning is generated when the variable is not set.[/CODE]
[/I][code=php]
mysql_select_db("database1");
[/code]
[code=php]
@mysql_select_db("database1");
[/code]
[code=php]
$db = @mysql_select_db($database);
if(!$db)
{
# output a custom error message here
}
else
{
# continue processing
}
[/code]
However, if you use @ to suppress error reporting, it now becomes incumbent upon you to do your own error-checking and -handling[/QUOTE]I agree with that but this case is rather different. It is quite normal to make a form sticky like so:
[code=php]value="<?php echo $_GET['index']; ?>"[/code]
which doesn't raise an error or a warning... but when error_reporting is set to E_ALL it raises a notice. Most people suppress that notice using isset() or empty() without further custom error handling so I don't really see a problem suppressing the error with @ and no custom handler in this instant.I agree with that but this case is rather different. It is quite normal to make a form sticky like so:[/QUOTE]
I agree with that but this case is rather different. It is quite normal to make a form sticky like so: [code=php]value="<?php echo $_GET['index']; ?>"[/code]
which doesn't raise an error or a warning... but when error_reporting is set to E_ALL it raises a notice. Most people suppress that notice using isset() or empty() without further custom error handling so I don't really see a problem suppressing the error with @ and no custom handler in this instant.[/QUOTE]
I hope not. Typeless variables are much easier to program with (ever try C++ going back and forth from *string to *int[] without static_cast?), and there's no harm in them. Since PHP automatically converts everything to what it needs, changing this functionality would break _every_ PHP script written as of now.[/QUOTE]
[code=php]
$string = "this is a string";
if($string == "this is a string"){
$string = TRUE;
}
else{
$string = FALSE;
}
if(!$string){
$string = 4;
}
else{
$string= 128;
}
[/code]
0.1.9 — BETA 5.19