简体   繁体   English

在.htaccess中设置php_value时发生意外错误?

[英]Accidental error in setting php_value in .htaccess?

So when I currently view phpinfo() in PHP, my error_reporting is set to some number, which represents the sum of all the error constant values, right? 因此,当我当前在PHP中查看phpinfo()时,我的error_reporting设置为某个数字,该数字表示所有错误常量值的总和,对吗?
Let's say, I accidentally set the value of error_reporting to some weird value by accident in .htaccess for example: 假设,我在.htaccess中意外地将error_reporting的值意外地设置为一些奇怪的值:

  1. -1 -1
  2. Value that is bigger than E_ALL (32768 for example, if I'm correct) 大于E_ALL的值(例如,如果我正确,则为32768)
  3. When setting it with a string, I do a typo (**E_AL** & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED) - typo in E_ALL 用字符串设置它时,我会(**E_AL** & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED)错字

What would happen, would it be set to some default value? 会发生什么,将其设置为某些默认值吗? Or from php.ini? 还是来自php.ini? I tried setting all the values above and they all were set in the Local Value without any problems. 我尝试设置以上所有值,并且都在“ Local Value中设置了所有Local Value没有任何问题。
I'm curious what will happen with any other value as well, will it default to php.ini or what? 我很好奇其他值也会发生什么,它将默认为php.ini还是什么?
Thanks! 谢谢!

PHP uses bitwise operators to determine whether the error level should be reported.. so whatever your integers value is as binary it would bitwise & to see if the error is reported. PHP使用按位运算符来确定是否应报告错误级别。因此,无论您的整数值是二进制值,它都将按位&查看是否报告了错误。

Eg if E_DEPRECATED were (not saying this is accurate): 01, E_WARNING is 10, E_NOTICE is 100, using E_DEPRECATED | 例如,如果使用E_DEPRECATED | E_DEPRECATED是(不是说这是正确的):01,E_WARNING是10,E_NOTICE是100。 E_WARNING | E_WARNING | E_NOTICE would give the binary 111, thus when an error is reported, like E_WARNING, it would take the value set, and bitwise & it to determine whether the report is displayed: E_NOTICE将提供二进制文件111,因此,当报告错误时(例如E_WARNING),它将采用设置的值,并按位与它确定是否显示报告:

111 & 010 = True, so the error would be reported. 111&010 = True,因此将报告错误。

if you just used E_DEPRECATED | 如果您只是使用过E_DEPRECATED | E_NOTICE, the binary is 101, so 101 & 010 = False, so the error won't be reported. E_NOTICE,二进制为101,所以101&010 = False,因此不会报告错误。

Each of these binaries can be converted to base10, 01 = 1, 10 = 2, 100 = 4 etc. 这些二进制文件中的每一个都可以转换为base10、01 = 1、10 = 2、100 = 4等。

So if you were curious as to which errors would be reported with your random integer you can do: 因此,如果您对随机整数会报告哪些错误感到好奇,可以执行以下操作:

int & E_WARNING in your PHP parser, if its True then the error will be shown, if its FALSE then the error will be ignored. int & E_WARNING在您的PHP解析器中,如果其为True,则将显示错误,如果其为FALSE,则将忽略该错误。

This is a good convention to learn, as its very useful when implementing logging on your application too, you can use the same system, and so you don't have to implement a long switch or if .. elseif .. block to determine whether a log level should be logged or not according to config. 这是一个很好的学习习惯,因为它在实现应用程序登录时也非常有用,您可以使用相同的系统,因此不必实施长时间的切换,也不必执行.. elseif ..块来确定是否是否根据配置记录日志级别。

  /**
   * Determines whether this message should be logged based on the provided type and the set threshold
   * @access protected
   * @param  int $type
   * @param  string   $name name of the log to check.
   * @return boolean
   */
  protected function should_log($type,$name='default') {
    return (bool) ($this->getConfig($name)->threshold & $type);
  }

so the threshold would be a binary number in your config (which uses constants for readability) then it bitwises & against the provided log type which returns True or False to determine whether to log the message to the logger by name $name ... much more optimised. 因此,阈值将是您配置中的二进制数(使用常量以提高可读性),然后按位和提供的日志类型返回True或False,以确定是否将消息以名称$name的形式记录到记录器中。更优化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM