开发者社区> 问答> 正文

php就是个蛋疼货, 不经过大脑. 热 : 配置报错 

5.5.1 如果输入的字符串是无效的十六进制字符串则抛出一个警告,

echo hex2bin('24234');

失败你就返回false, 它非得抛个警告出来. 开发组这是往delphi方向发展吗?

展开
收起
kun坤 2020-06-04 13:13:03 614 0
1 条回答
写回答
取消 提交回答
  • @屏蔽掉吧######@ 也没经过大脑呀.######php向java靠拢,注意数据类型(严谨性)是语言完善进步的表现。 ######类型没错呀. 它是传入一个字符串类型,######主要是告诉你这里是错误的吧,不能这样用。######坐等喷子的到来。######你就是个喷子############ http://cn2.php.net/hex2bin
    不想看,你可以用@抑制错误输出。

    php.ini里配置error_reporting = E_ALL就意味着输出和记录所有错误信息,包括Fatal error、Warning、Notice等各种信息,php.ini配置里有详细的说明:

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; Error handling and logging ;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; This directive informs PHP of which errors, warnings and notices you would like
    ; it to take action for. The recommended way of setting values for this
    ; directive is through the use of the error level constants and bitwise
    ; operators. The error level constants are below here for convenience as well as
    ; some common settings and their meanings.
    ; By default, PHP is set to take action on all errors, notices and warnings EXCEPT
    ; those related to E_NOTICE and E_STRICT, which together cover best practices and
    ; recommended coding standards in PHP. For performance reasons, this is the
    ; recommend error reporting setting. Your production server shouldn't be wasting
    ; resources complaining about best practices and coding standards. That's what
    ; development servers and development settings are for.
    ; Note: The php.ini-development file has this setting as E_ALL. This
    ; means it pretty much reports everything which is exactly what you want during
    ; development and early testing.
    ;
    ; Error Level Constants:
    ; E_ALL             - All errors and warnings (includes E_STRICT as of PHP 5.4.0)
    ; E_ERROR           - fatal run-time errors
    ; E_RECOVERABLE_ERROR  - almost fatal run-time errors
    ; E_WARNING         - run-time warnings (non-fatal errors)
    ; E_PARSE           - compile-time parse errors
    ; E_NOTICE          - run-time notices (these are warnings which often result
    ;                     from a bug in your code, but it's possible that it was
    ;                     intentional (e.g., using an uninitialized variable and
    ;                     relying on the fact it's automatically initialized to an
    ;                     empty string)
    ; E_STRICT          - run-time notices, enable to have PHP suggest changes
    ;                     to your code which will ensure the best interoperability
    ;                     and forward compatibility of your code
    ; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup
    ; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's
    ;                     initial startup
    ; E_COMPILE_ERROR   - fatal compile-time errors
    ; E_COMPILE_WARNING - compile-time warnings (non-fatal errors)
    ; E_USER_ERROR      - user-generated error message
    ; E_USER_WARNING    - user-generated warning message
    ; E_USER_NOTICE     - user-generated notice message
    ; E_DEPRECATED      - warn about code that will not work in future versions
    ;                     of PHP
    ; E_USER_DEPRECATED - user-generated deprecation warnings
    ;
    ; Common Values:
    ;   E_ALL (Show all errors, warnings and notices including coding standards.)
    ;   E_ALL & ~E_NOTICE  (Show all errors, except for notices)
    ;   E_ALL & ~E_NOTICE & ~E_STRICT  (Show all errors, except for notices and coding standards warnings.)
    ;   E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR  (Show only errors)
    ; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
    ; Development Value: E_ALL
    ; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
    ; http://php.net/error-reporting

    ######回复 @eechen : 还能去掉警告的日志? 这是下下下下策呀, 亲.######回复 @Tuesday : 你配置 error_reporting = E_ALL & ~E_WARNING 重启服务,就可以不记录 WARNING 信息。######php log日志会记录在案. 运行久了, 日志里面就全部是这种没意义的警告信息.###### 这个你觉得没意义吗?
    我见过不少对执行结果不做任何判断的人。
    或许应该抛个异常才能接受。 ######回复 @Tuesday : 第一,程序遇到意外的数据难道不应该记录? 第二,程序遇到意外的数据难道不应该退出? 第三,我没说过让php内置函数抛异常的话,如果很有精力的人可以修改源码重新编译。######回复 @夏涌升 : 求详细,php怎么对内置函数抛出你所谓的异常?######回复 @Tuesday : 什么叫完全没错。。。错误/异常 如果输入的十六进制字符串是奇数长数或者无效的十六进制字符串将会抛出 E_WARNING 级别的错误。 不过要是我,在这个地方我会选择抛出异常。 我不认为返回false是个好主意,如果有人在关键业务拿false去当正常结果用,结果谁都不报异常,你想想有多悲剧。######string hex2bin ( string $data ) 这是手册的说明. 传入参数是字符串, 使用方法完全没错,######如果发生错误就返回false 你如何知道具体的错误信息?动动手try一下 也不会占用你多少时间######try{ echo hex2bin('242'); } catch(Exception $e) { print_r($e); } 求测!!!!!!!!!!!!!!!!!!! php的try更蛋疼.######楼主好腻骇######异常明显比返回值更好用 ######用try试过再说.

    2020-06-05 13:21:53
    赞同 展开评论 打赏
问答分类:
PHP
问答地址:
问答排行榜
最热
最新

相关电子书

更多
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载
PHP安全开发:从白帽角度做安全 立即下载
复杂PHP系统性能瓶颈排查及优化 立即下载