This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 9 years ago.
I found this tutorial on making a try it editor for a website.
I understood everything in the code except the # in the result.php:
Result.php
<?php
$myCode = #$_REQUEST["code"];
print $myCode ;
?>
Also I tried removing it from the code and nothing changed, so what does it do?
# is a PHP error control operator
PHP supports one error control operator: the at sign (#). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored
Reference
http://php.net/manual/en/language.operators.errorcontrol.php
Example
<?php
/* Intentional file error */
$my_file = #file ('non_existent_file') or
die ("Failed opening file: error was '$php_errormsg'");
// this works for any expression, not just functions:
$value = #$cache[$key];
// will not issue a notice if the index $key doesn't exist.
?>
It ignores/suppresses error messages - see Error Control Operators in the PHP manual.
PHP supports one error control operator: the at sign (#). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
If you have set a custom error handler function with set_error_handler() then it will still get called, but this custom error handler can (and should) call error_reporting() which will return 0 when the call that triggered the error was preceded by an #.
so any error in $myCode = #$_REQUEST["code"]; will be ignored.
Related
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
What is the use of the # symbol in PHP?
(11 answers)
Closed 4 years ago.
I would like to know the use of # character in WordPress. For example:
if ( $plugins_dir = # opendir( WP_CONTENT_DIR ) ) { ... }
Also what is the difference between #opendir and # opendir, i.e. using a space after # character.
I am new to WordPress.
That is a part of the PHP language syntax and not strictly part of WordPress itself. The # symbol denotes that any errors from that function should be suppressed in case it fails for some reason.
This is called an Error Control Operator and you can find more information about it on the PHP documentation website. It stops errors of all types from being displayed (which can be a good or bad thing depending on what is happening).
There doesn't seem to be any difference between having a space and not having one. It will just depend on your style of writing code.
PHP supports one error control operator: the at sign (#). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
<?php
/* Intentional file error */
$my_file = #file ('non_existent_file') or
die ("Failed opening file: error was '$php_errormsg'");
// this works for any expression, not just functions:
$value = #$cache[$key];
// will not issue a notice if the index $key doesn't exist.
?>
This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 9 years ago.
I'm following a PHP/AJAX tutorial on form validation. (I'm new to php!).
Could someone explain the syntax of this line:
<?=#$_REQUEST['username']?>
The context is the value attribute of an input field.
I know how $_REQUEST works. I just don't get the <?=# part. I understand <? can be used in lieu of <?php (but isn't always supported!) and <?=$variable?> is special syntax for echoing variables. What does the # symbol do?
Thanks.
Links:
Form validation tutorial
Explanation for special syntax
<?= ?> is the short echo syntax. <?=$var?> is equivalent to <?php echo $var; ?>.
From the PHP manual:
echo also has a shortcut syntax, where you can immediately follow the opening tag with an equals sign. Prior to PHP 5.4.0, this short syntax only works with the short_open_tag configuration setting enabled.
# is the error suppression operator. When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.
In short, <?=#$_REQUEST['username']?> will try to print out the value of $_REQUEST['username'] (without ouputting any errors). It's not a good practice and shouldn't be used in your code. If you don't want to display the errors, turn off display_errors in your php.ini configuration and log them instead.
This question already has answers here:
'At' symbol before variable name in PHP: #$_POST
(5 answers)
Closed 9 years ago.
Can you please tell me the difference between
$variable and #$variable in php
<?php
curl function abc
{
get information of url and return information string
}
$html=abc();
$doc=DOMDocument();
#$doc->LoadHTML($html);
?>
here if we take normal variable it gives error why its so
and whats the difference
A # before a function call means "suppress warnings".
So, #$doc->LoadHTML($html); suppresses warnings from the method call (LoadHTML()).
In general this is a bad idea, because the warnings mean you are doing something wrong, and you would better fix that instead of playing deaf.
The # operator tells the compiler to ignore the error that PHP could give, its advised not to use it.
Suppress warning when accessing that property, if for instance $html was undefined then no error is displayed, see http://davidwalsh.name/suppress-php-errors-warnings
# is called Error Control Operator, it can be prepended before expression to disable error reporting for that expression.
Please see this post for more information: Suppress error with # operator in PHP
This question already has answers here:
What is the use of the # symbol in PHP?
(11 answers)
Closed 9 years ago.
What is the meaning of ##variable in php ?
$fix=##parts;
# is used to suppress any errors that may occur on this line of the code
http://php.net/manual/en/language.operators.errorcontrol.php
When prepended to an expression in PHP, any error messages that might
be generated by that expression will be ignored.
I would not recommend using it at all because this may result in failure of noticing some important error/warning and make debugging a havoc. On a production environment use error_reporting setting that will prevent any errors or warning from showing up while on a development server I would recommend to turn on any error reporting
PHP supports one error control operator: the at sign (#). When
prepended to an expression in PHP, any error messages that might be
generated by that expression will be ignored.
Link : PHP.net explanation
The #operator turns off error handling.
This question already has answers here:
Closed 12 years ago.
Possible Duplicates:
Reference - What does this symbol mean in PHP?
What does # mean in PHP?
I have a line in my code which looks like this:
#mysql_select_db($dbname) or die( "Error: Unable to select database");
It works, but I want to know what the # does and why it is there.
The # symbol suppresses any errors and notices for the expression it precedes.
See this reference: PHP Error Control Operators
PHP supports one error control
operator: the at sign (#). When
prepended to an expression in PHP, any
error messages that might be generated
by that expression will be ignored.
In this case, the # will suppress the regular PHP database connection error (which may contain sensitive information). In case of a connection error, the "or die" part will be executed, failing with a generic error message. The line is probably copied from a "quick and dirty" example.
Using the error suppression operator # is considered bad style, especially when other forms of error handling are missing. It complicates debugging - how can you find out about in error without any indication that it occured? In a production system it's better to log all errors to a file and suppress the rendering of errors on the page. You could do that in the php.ini file or (if you are on a shared host and not allowed to make config changes) with the following code.
ini_set('display_errors', false);
ini_set('log_errors', true);
ini_set('error_log', '/var/log/apache/php-errors.log');
It suppresses all error output. Generally, you shouldn't use it unless you have a good reason. I don't know why it is used in the example you posted, or why die() is used. The error should be caught and processed accordingly. The select may fail for a number of reasons, some perhaps recoverable. Like no connection to the database established.