ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
PHP µ÷ÊÔ¼¼ÊõÊÖ²á
(http://blog.csdn.net/heiyeshuwu) ²ÎÓëÈË laruence (http://www.laruence.com/) ±àдÈÕÆÚ 2010-6-13
                                                                                            °æ±¾ 1.0.0 ×÷Õß heiyeluren




PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0                 Ŀ¼ 1 ÄÚÖà API Êä³öµ÷ÊÔ
.................................................................................................................................... 2 1.1 »ù±¾
µ÷ÊÔ
API ..............................................................................................................................................
. 2 1.1.1 echo
(print): .........................................................................................................................................
2 1.1.2
printf ............................................................................................................................................
........ 2 1.1.3
print_r¡¢var_dump(var_export)¡¢debug_zval_dump ..................................................................
....... 3 1.2 ´íÎó¿ØÖƺÍÈÕÖ¾¼Ç¼µ÷ÊÔ
........................................................................................................................... 6 1.2.1 ´íÎóÑ¡
Ïî¿ØÖÆ .................................................................................................................................... 6
1.2.2 ´íÎóÅ׳öºÍ´¦Àí
................................................................................................................................ 8 1.2.3 ʹÓÃ
´íÎóÒÖÖÆ·û ...............................................................................................................................
11 1.2.4 ÈÕÖ¾¼Ç¼
........................................................................................................................................... 11 2
ä¯ÀÀÆ÷µ÷ÊÔ
............................................................................................................................................... 13
2.1 Ò³ÃæÊä³öµ÷ÊÔ
............................................................................................................................................. 13
2.2 FirePHP µ÷ÊÔ
.............................................................................................................................................. 14
2.2.1 ÆÕͨ±äÁ¿¼à²â
.................................................................................................................................. 15 2.2.2 µ÷
ÓÃÕ»¼à²â ......................................................................................................................................
17 2.2.3 ¼à²âÅ׳öÒì³£
.................................................................................................................................. 18 2.2.4 ×é
ÏÔʾÐÅÏ¢ ......................................................................................................................................
18 3 IDE µ÷ÊÔ
....................................................................................................................................................
19 3.1 »ù±¾³£Óà IDE ½éÉÜ
.................................................................................................................................... 19 3.1.1
Vim ..............................................................................................................................................
...... 19 3.1.2 Zend
Studio .......................................................................................................................................
19 3.1.3
Eclipse ........................................................................................................................................
....... 21 3.1.4
NetBeans ....................................................................................................................................
....... 22 3.2 IDE µ÷ÊÔ
.....................................................................................................................................................
. 23 3.2.1 Zend Studio + Zend
Debugger .......................................................................................................... 23 3.2.2 Eclipse
(PDT) + Xdebug ................................................................................................................... 31
3.2.3 Vim + Xdebug +
DBGp ..................................................................................................................... 37 4 PHP ÐÔ
Äܵ÷ÊÔ¼¼
Êõ.................................................................................................................................... 39 4.1
»ù±¾Ê±¼äÕ¼Óüà²â
..................................................................................................................................... 39 4.2 ʹ
ÓÃ Xdebug ½øÐÐÐÔÄÜ·ÖÎö
.................................................................................................................... 39 4.2.1 °²×°ÅäÖãº
...................................................................................................................................... 41 4.3
APD(Advanced PHP
Debugger) .................................................................................................................. 46 4.3.1
°²×°ÅäÖÃ
.......................................................................................................................................... 46
4.3.2 ʹÓÃ
APD .........................................................................................................................................
46 4.4 ʹÓà Xhprof ½øÐÐÐÔÄÜ·ÖÎö
...................................................................................................................... 47 4.4.1 Xhprof µÄ
Óŵ㣺 ............................................................................................................................. 47 5
PHP µ¥Ôª²âÊÔ¼¼Êõ
.................................................................................................................................... 51 5.1
PHPUnit ......................................................................................................................................
................. 51 ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 1 Ò³ ¹² 51 Ò³

PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0               1 ÄÚÖà API Êä³öµ÷ÊÔ ÄÚÖà API Ö÷ÒªÊÇʹÓà PHP ÄÚÖõĺ¯ÊýºÍ
ÅäÖÃÀ´½øÐе÷ÊÔ¹¤×÷£¬´ó²¿·ÖÇé¿ö£¬ÊÇÄ¿Ç°Á÷ÐÐÖ÷ÒªµÄ·½Ê½£¬ Ò²ÊǼòµ¥ÓÐЧµÄ·½Ê½¡£ һЩ»ù
±¾µÄ API£ºecho (print)¡¢print_r¡¢var_dump(var_export)¡¢debug_zval_dump¡¢
debug_print_backtrace(debug_backtrace) һЩ»ù±¾µÄÅäÖãº
display_errors¡¢log_errors¡¢error_reporting¡¢error_log 1.1 »ù±¾µ÷ÊÔ API 1.1.1
echo (print): ÕâÊÇ×î¼òµ¥µÄÊä³öÊý¾Ýµ÷ÊÔ·½·¨£¬Ò»°ãÓÃÀ´Êä³ö±äÁ¿Öµ£¬»òÕßÄ㲻ȷ¶¨³ÌÐòÖ´ÐÐ
µ½ÁËÄĸö·ÖÖ§µÄÇé¿öÏÂÊÇÓᣠ´úÂëʾÀý£º Ö´Ðнá¹û£º Çå³þµÄ¿´µ½´úÂë·ÖÖ§Ö´Ðе½Á˵ÚÈý¸öÅÐ
¶Ï·ÖÖ§¡£ 1.1.2 printf printf º¯Êý³£ÓÃÀ´µ÷ÊÔÊä³öһЩÆäËûÊä³ö²»ÄÜÕýÈ·Êä³öµÄ±äÁ¿, ±ÈÈçÔÚ
PHP ÖÐ,¸¡µãÊýºÍÕûÊýÖ®¼ä¾­³£»á Ôì³ÉÃÔ»ó. ´úÂëʾÀý: Ö´Ðнá¹û: ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ
2 Ò³ ¹² 51 Ò³


ill
PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 ÕâÖÖÇé¿öÏÂ, ҪŪÇåΪʲô»áÓÐÕâÖÖ²îÒì, ¾ÍÒªÓõ½ printf ÁË ´úÂëʾÀý: Êä
³ö: 1.1.3 print_r¡¢var_dump(var_export)¡¢debug_zval_dump Õâ¸öÖ÷ÒªÊÇÓÃÀ´Êä³ö±äÁ¿
Êý¾ÝÖµ£¬ÌرðÊÇÊý×éºÍ¶ÔÏóÊý¾Ý£¬Ò»°ãÎÒÃÇÔڲ鿴½Ó¿Ú·µ»ØÖµ£¬»òÕßijЩ²»Ì« È·¶¨±äÁ¿µÄʱ
ºò£¬¶¼¿ÉÒÔʹÓÃÕâÁ½¸ö API¡£ ²âÊÔ´úÂ룺 ²é¿´Êä³ö£º var_dump »á¶îÍâÊä³öÊý¾ÝÀàÐÍ: ºÚҹ·ÈË
µÄ¿ªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 3 Ò³ ¹² 51 Ò³

Pintf illillil
PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 [rint_r Êä³ö£º¸ñʽºÜÕûÆ룬¸ú var_dump µÄÇø±ðÊÇûÓÐÀàÐÍÊý¾Ý£¬²¢ÇÒ²¼
¶ûÖµµÄ false ºÍÖµ NULL Êä³öΪ¿Õ var_export Êä³ö£¬ËùÓеÄÊý¾ÝÊÇ¿ÉÒÔ×÷Ϊ×éÖ¯ºÃµÄ±äÁ¿Êä³ö
µÄ£¬¶¼ÊÇÄܹ»×÷Ϊֱ½Ó¸³ÖµÊ¹Ó㺠ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 4 Ò³ ¹² 51 Ò³

PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 ÐèҪעÒâµÄÒ»µãÊÇ, var_export ¶ÔÓÚ×ÊÔ´Ð͵ıäÁ¿»áÊä³ö NULL [1]
debug_zval_dump Êä³ö½á¹û¸ú var_dump ÀàËÆ£¬Î¨Ò»Ôö¼ÓµÄÒ»¸öÖµÊÇ refcount£¬¾ÍÊǼǼһ¸ö
±äÁ¿±»Òý ÓÃÁ˶àÉٴΣ¬ÕâÊÇ php µÄ copy on write (дʱ¸´ÖÆ) µÄ»úÖƵÄÒ»¸öÖØÒªÌصã [2] ¡£
debug_print_backtrace ¿ÉÒÔÈÃÎÒÃDz鿴Õû¸ö³ÌÐòµÄµ÷ÓÃÕ»£¬ÓÃÀ´²é¿´Ë²¼äº¯Êýµ÷ÓÃÕ»£¬·½±ãÔÚ
³ö´íʱ²é ¿´Ö´ÐÐÉÏÏÂÎÄ:. 1. 1 var_export Óë var_dump µÄ²»Í¬: http://www.laruence.com/2008/04/03/15.html
2 ÉîÈë̽ÌÖ PHP ÖеÄÄÚ´æ¹ÜÀíÎÊÌâ: http://tech.sina.com.cn/s/2006-10-26/09151204364.shtm ÉîÈëÀí½â PHP Ô­
ÀíÖ®±äÁ¿·ÖÀë: http://www.laruence.com/2008/09/19/520.html ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 5 Ò³ ¹² 51 Ò³

A


PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 ²é¿´Êä³ö£¬Ã÷È·µÄÊä³öÁËÈý¸öº¯ÊýµÄµ÷ÓÃÕ»ÐÅÏ¢£º                                      1.2 ´íÎó¿ØÖƺÍ
ÈÕÖ¾¼Ç¼µ÷ÊÔ 1.2.1 ´íÎóÑ¡Ïî¿ØÖÆ Php.ini ÅäÖÃÖУ¬¸ú´íÎóÏà¹ØµÄÑ¡ÏîÖ÷Òª£º
error_reporting¡¢display_errors¡¢log_errors¡¢error_log µÈ¼¸¸ö£¬ ÕâЩѡÏîÔÚÒ»°ãÓï·¨¼¶±ðµÄ
µ÷ÊÔÊǺÜÓаïÖúµÄ¡£ Error_reporting ÊÇÉèÖà PHP ´íÎóÏÔʾ¼¶±ð£¬PHP µÄ´íÎóÏÔʾ¼¶±ðÓÐÕâô
¼¸¸ö£º value constant 1 E_ERROR 2 E_WARNING 4 E_PARSE 8 E_NOTICE 16
E_CORE_ERROR 32 E_CORE_WARNING 64 E_COMPILE_ERROR 128
E_COMPILE_WARNING 256 E_USER_ERROR 512 E_USER_WARNING 1024
E_USER_NOTICE 6143 E_ALL 2048 E_STRICT 4096 E_RECOVERABLE_ERROR E_ALL
°üº¬³ýÈ¥ E_STRICT ÒÔÍâµÄËùÓдíÎóÐÅÏ¢,Ò»°ãµÄÑ¡ÏîÊÇÏÔʾ Notice ÒÔÉϼ¶±ðµÄÏûÏ¢£¬¾ÍÊÇÉè
ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 6 Ò³ ¹² 51 Ò³

PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 ÖÃΪ£º error_reporting = E_ALL & ~E_NOTICE ÕâÑù¾Í»áÏÔʾ°üÀ¨¾¯¸æ¡¢
ÖÂÃü´íÎóµÈµÈ¹Ø¼ü´íÎó£¬Ò»°ã Notic ´íÎó¾ÍÊÇ°üÀ¨±äÁ¿Î´¶¨ÒåÖ®ÀàµÄ¶¨Ò壬±È ÈçÕâÑùµÄ´úÂ룺
(Notice ´íÎóÒ»°ã²»ÊÇÌ«ÑÏÖØ£¬³ÌÐò»¹»á»á¼ÌÐøÖ´ÐÐ) Ö´ÐоͻáÌáʾ£¬Èç¹ûÉ趨ÁËÆÁ±Î Notice£¬
¾Í²»»áÌáʾ´íÎó£º ¾¯¸æÀà´íÎóÒ»°ã¶¼ÊÇ±È Notice ¸üÑÏÖصĴíÎ󣬱ÈÈçÊý×é²»´æÔھͽøÐÐÑ­»·
ÊÇ×î³£¼ûµÄ£º Ö´Ðоͻᱨһ¸ö Warning£º (Warning ´íÎóÑÏÖس̶ÈΪÖеȣ¬³ÌÐò»á¼ÌÐøÖ´ÐУ¬
µ«Êǽ¨Òé½â¾ö) ÖÂÃü´íÎóͨ³£¶¼ÊÇÓï·¨¼¶±ðµÄ´íÎ󣬱ÈÈçȱÉٷֺŽáβÖ®ÀàµÄ£º (ÖÂÃü´íÎóÔòÊÇ
³ÌÐò»áÖÕÖ¹Ö´ÐУ¬Ò»¶¨Òª½â ¾ö) ±¨´íÌáʾ£º Error_reporting ͬÑù¿ÉÒÔ×÷Ϊһ¸ö PHP º¯ÊýÀ´µ÷
Ó㺠ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 7 Ò³ ¹² 51 Ò³

Parse errer: syntax errer, unexpected Send in [Iummand line cede un line 1

PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 display_errors ÊÇÉ趨ÊÇ·ñÔÚ PHP ½Å±¾Ö´ÐÐÊä³öµÄʱºòÊä³ö´íÎóÐÅÏ¢£¬È±
Ê¡ÊÇ£º Ò»°ãÔÚÏßÏ¿ª·¢µ÷ÊÔ»·¾³£¬ÎªÁ˱ãÓÚµ÷ÊÔ£¬»á´ò¿ª´íÎóÏÔʾѡÏÔÚÏßÉÏΪÁ˲»Ð¹Â¶Ãô
¸ÐÐÅÏ¢£¬Ò»°ã»á°É display_errors ÉèÖÃΪ Off¡£ ÕâÀïÓÖ´øÀ´ÁËÒ»¸öеÄÎÊÌ⣬Èç¹ûÏßÉϱ¨´í
ÁË£¬ÎÒÃÇÈçºÎ²é¿´µ½´íÎó£¿ÄÇô¾ÍÐèÒª log_errors Ñ¡ÏîÁË¡£Õâ ¸öÑ¡ÏîÊÇÉ趨ÊÇ·ñ¼Ç¼´íÎóÈÕ
Ö¾£¬Ò»°ãÑ¡ÏîÊÇ Off£¬µ«ÊÇÈç¹ûÊÇÔÚÏßÉϹ¤×÷»·¾³£¬½¨Òé°ÑËü´ò¿ª£º ´ò¿ªÁË log_errors Ñ¡ÏîµÄ
ͬʱ£¬Ò²ÒªÉèÖôíÎóÈÕÖ¾¼Ç¼µÄĿ¼ѡÏî error_log £º ÄÇôÔÚ error_reporting µÄÉèÖ÷¶Î§
ÄÚ£¬PHP ½âÎöÏà¹ØµÄ´íÎó¾ÍÄÜÔÚÈÕÖ¾Àï¿´µ½ÁË¡£ 1.2.2 ´íÎóÅ׳öºÍ´¦Àí ´íÎóÅ׳öºÍ´¦ÀíÖ÷
ÒªÊÇ˵ÎÒÃÇÔÚ³ÌÐòÖУ¬Äܹ»×Ô¼º´¥·¢´íÎ󣬻òÕßÊÇ×Ô¼º½Ø»ñ´¦Àí´íÎó£¬ÀàËÆÓÚÃæÏò¶Ô Ïó±à³ÌÀï
µÄÒì³£´¦Àí throw Å׳öÒì³££¬catch ½Ø»ñÒì³£Ò»¸ö˼·¡£
trigger_error¡¢set_error_handler¡¢set_exception_handler ÕâÈý¸ö api Ö÷Òª¾ÍÊÇ´¦Àí´íÎóÅ׳ö
ºÍ´¦ÀíÄÚÖú¯Êý¡£ ʹÓà trgger_error ¿ÉÒÔ´¥·¢Ò»¸ö´íÎ󣬴¥·¢¼¶±ð¸úÉÏÎÄµÄ error_reporting µÄ
É趨¼¶±ðÒ»Ö£¬Ö÷ÒªÊÇÄܹ»´¥ ·¢µÄÊÇ E_USER_ERROR, E_USER_WARNING,
E_USER_NOTICE ÈýÖÖ¼¶±ðµÄ´íÎó£¬Èç¹û²»×ö´¦Àí£¬ÄÇô ÔÚ³ÌÐòÖ´Ðоͻᱨ´í£¬´íÎóÌáʾ¸ú
ÉÏÎÄÃèÊö²î²»¶à£¬»á³öÏÖ Fatal Error¡¢Warning¡¢Notice ÈýÖÖ´íÎóÏÔʾ¡£ trigger_error ÊÇÒ»¸ö
Å׳ö´íÎóµÄº¯Êý£¬¿ÉÒÔÅ׳öÈκÎÓû§¼¶±ð´íÎó£¬ÔÚ·ÇÃæÏò¶ÔÏóʱ´úµÄ±à³ÌÀ¿ÉÒÔ×÷ Ϊһ¸öÌá
ʾ´íÎóµÄÒ»ÖÖ·½Ê½¡£ ʾÀý£¬ÎÒÃÇÒ»¸öº¯ÊýÐèÒªÊäÈëÒ»¸öÕûÐεıäÁ¿£¬Èç¹û²»ÊǾʹ¥·¢Ò»¸ö¾¯
¸æ£º ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 8 Ò³ ¹² 51 Ò³

errors a , , nr errur_ 386 ; H5 stated annue, yuu're Strongly tu use errnr logging in place nF 381 ; error displaying on
production web sitos. 382 errors unrecognized text Un

PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 Êä³ö½á¹û£¬¿ÉÒÔ¿´µ½ÓÐÒ»¸ö¾¯¸æ²úÉúÁË£º set_error_handler ˵ÎÒÃÇ·¢Éú
ÁË´íÎóµÄʱºò£¬ÓÃʲô´¦Àíº¯ÊýÀ´´¦Àí£¬Ò»°ãÕâ¸ö¶¼ÊÇÓÃÀ´Õë¶Ô trigger_error Ö®ºóÀ´½øÐдíÎó
´¦ÀíµÄ£¬Á½¸öº¯Êý½áºÏ£¬ÎÒÃÇ¿ÉÒÔ¹¹½¨Ò»¸ö¼òµ¥ÓÐЧµÄ´íÎóʶ±ðºÍ¼Ç¼µÄ¹¦ÄÜ¡£ ÎÒÃÇÏȱàдһ
¸ö´íÎó´¦Àíº¯Êý£º ÔÙ±àдһ¸ö´íÎóµ÷Ó㬲¢ÇÒÖ´ÐÐ: ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 9 Ò³ ¹² 51 Ò³

More Related Content

PHP-Debug-Manual-public

  • 1. PHP µ÷ÊÔ¼¼ÊõÊÖ²á (http://blog.csdn.net/heiyeshuwu) ²ÎÓëÈË laruence (http://www.laruence.com/) ±àдÈÕÆÚ 2010-6-13 °æ±¾ 1.0.0 ×÷Õß heiyeluren PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 Ŀ¼ 1 ÄÚÖà API Êä³öµ÷ÊÔ .................................................................................................................................... 2 1.1 »ù±¾ µ÷ÊÔ API .............................................................................................................................................. . 2 1.1.1 echo (print): ......................................................................................................................................... 2 1.1.2 printf ............................................................................................................................................ ........ 2 1.1.3 print_r¡¢var_dump(var_export)¡¢debug_zval_dump .................................................................. ....... 3 1.2 ´íÎó¿ØÖƺÍÈÕÖ¾¼Ç¼µ÷ÊÔ ........................................................................................................................... 6 1.2.1 ´íÎóÑ¡ Ïî¿ØÖÆ .................................................................................................................................... 6 1.2.2 ´íÎóÅ׳öºÍ´¦Àí ................................................................................................................................ 8 1.2.3 ʹÓà ´íÎóÒÖÖÆ·û ............................................................................................................................... 11 1.2.4 ÈÕÖ¾¼Ç¼ ........................................................................................................................................... 11 2 ä¯ÀÀÆ÷µ÷ÊÔ ............................................................................................................................................... 13 2.1 Ò³ÃæÊä³öµ÷ÊÔ ............................................................................................................................................. 13 2.2 FirePHP µ÷ÊÔ .............................................................................................................................................. 14 2.2.1 ÆÕͨ±äÁ¿¼à²â .................................................................................................................................. 15 2.2.2 µ÷ ÓÃÕ»¼à²â ...................................................................................................................................... 17 2.2.3 ¼à²âÅ׳öÒì³£ .................................................................................................................................. 18 2.2.4 ×é ÏÔʾÐÅÏ¢ ...................................................................................................................................... 18 3 IDE µ÷ÊÔ .................................................................................................................................................... 19 3.1 »ù±¾³£Óà IDE ½éÉÜ .................................................................................................................................... 19 3.1.1 Vim .............................................................................................................................................. ...... 19 3.1.2 Zend Studio ....................................................................................................................................... 19 3.1.3 Eclipse ........................................................................................................................................ ....... 21 3.1.4 NetBeans .................................................................................................................................... ....... 22 3.2 IDE µ÷ÊÔ .....................................................................................................................................................
  • 2. . 23 3.2.1 Zend Studio + Zend Debugger .......................................................................................................... 23 3.2.2 Eclipse (PDT) + Xdebug ................................................................................................................... 31 3.2.3 Vim + Xdebug + DBGp ..................................................................................................................... 37 4 PHP ÐÔ Äܵ÷ÊÔ¼¼ Êõ.................................................................................................................................... 39 4.1 »ù±¾Ê±¼äÕ¼Óüà²â ..................................................................................................................................... 39 4.2 ʹ Óà Xdebug ½øÐÐÐÔÄÜ·ÖÎö .................................................................................................................... 39 4.2.1 °²×°ÅäÖ㺠...................................................................................................................................... 41 4.3 APD(Advanced PHP Debugger) .................................................................................................................. 46 4.3.1 °²×°ÅäÖà .......................................................................................................................................... 46 4.3.2 ʹÓà APD ......................................................................................................................................... 46 4.4 ʹÓà Xhprof ½øÐÐÐÔÄÜ·ÖÎö ...................................................................................................................... 47 4.4.1 Xhprof µÄ Óŵ㣺 ............................................................................................................................. 47 5 PHP µ¥Ôª²âÊÔ¼¼Êõ .................................................................................................................................... 51 5.1 PHPUnit ...................................................................................................................................... ................. 51 ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 1 Ò³ ¹² 51 Ò³ PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 1 ÄÚÖà API Êä³öµ÷ÊÔ ÄÚÖà API Ö÷ÒªÊÇʹÓà PHP ÄÚÖõĺ¯ÊýºÍ ÅäÖÃÀ´½øÐе÷ÊÔ¹¤×÷£¬´ó²¿·ÖÇé¿ö£¬ÊÇÄ¿Ç°Á÷ÐÐÖ÷ÒªµÄ·½Ê½£¬ Ò²ÊǼòµ¥ÓÐЧµÄ·½Ê½¡£ һЩ»ù ±¾µÄ API£ºecho (print)¡¢print_r¡¢var_dump(var_export)¡¢debug_zval_dump¡¢ debug_print_backtrace(debug_backtrace) һЩ»ù±¾µÄÅäÖ㺠display_errors¡¢log_errors¡¢error_reporting¡¢error_log 1.1 »ù±¾µ÷ÊÔ API 1.1.1 echo (print): ÕâÊÇ×î¼òµ¥µÄÊä³öÊý¾Ýµ÷ÊÔ·½·¨£¬Ò»°ãÓÃÀ´Êä³ö±äÁ¿Öµ£¬»òÕßÄ㲻ȷ¶¨³ÌÐòÖ´ÐÐ µ½ÁËÄĸö·ÖÖ§µÄÇé¿öÏÂÊÇÓᣠ´úÂëʾÀý£º Ö´Ðнá¹û£º Çå³þµÄ¿´µ½´úÂë·ÖÖ§Ö´Ðе½Á˵ÚÈý¸öÅÐ ¶Ï·ÖÖ§¡£ 1.1.2 printf printf º¯Êý³£ÓÃÀ´µ÷ÊÔÊä³öһЩÆäËûÊä³ö²»ÄÜÕýÈ·Êä³öµÄ±äÁ¿, ±ÈÈçÔÚ PHP ÖÐ,¸¡µãÊýºÍÕûÊýÖ®¼ä¾­³£»á Ôì³ÉÃÔ»ó. ´úÂëʾÀý: Ö´Ðнá¹û: ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 2 Ò³ ¹² 51 Ò³ ill PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 ÕâÖÖÇé¿öÏÂ, ҪŪÇåΪʲô»áÓÐÕâÖÖ²îÒì, ¾ÍÒªÓõ½ printf ÁË ´úÂëʾÀý: Êä ³ö: 1.1.3 print_r¡¢var_dump(var_export)¡¢debug_zval_dump Õâ¸öÖ÷ÒªÊÇÓÃÀ´Êä³ö±äÁ¿ Êý¾ÝÖµ£¬ÌرðÊÇÊý×éºÍ¶ÔÏóÊý¾Ý£¬Ò»°ãÎÒÃÇÔڲ鿴½Ó¿Ú·µ»ØÖµ£¬»òÕßijЩ²»Ì« È·¶¨±äÁ¿µÄʱ ºò£¬¶¼¿ÉÒÔʹÓÃÕâÁ½¸ö API¡£ ²âÊÔ´úÂ룺 ²é¿´Êä³ö£º var_dump »á¶îÍâÊä³öÊý¾ÝÀàÐÍ: ºÚҹ·ÈË µÄ¿ªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 3 Ò³ ¹² 51 Ò³ Pintf illillil
  • 3. PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 [rint_r Êä³ö£º¸ñʽºÜÕûÆ룬¸ú var_dump µÄÇø±ðÊÇûÓÐÀàÐÍÊý¾Ý£¬²¢ÇÒ²¼ ¶ûÖµµÄ false ºÍÖµ NULL Êä³öΪ¿Õ var_export Êä³ö£¬ËùÓеÄÊý¾ÝÊÇ¿ÉÒÔ×÷Ϊ×éÖ¯ºÃµÄ±äÁ¿Êä³ö µÄ£¬¶¼ÊÇÄܹ»×÷Ϊֱ½Ó¸³ÖµÊ¹Ó㺠ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 4 Ò³ ¹² 51 Ò³ PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 ÐèҪעÒâµÄÒ»µãÊÇ, var_export ¶ÔÓÚ×ÊÔ´Ð͵ıäÁ¿»áÊä³ö NULL [1] debug_zval_dump Êä³ö½á¹û¸ú var_dump ÀàËÆ£¬Î¨Ò»Ôö¼ÓµÄÒ»¸öÖµÊÇ refcount£¬¾ÍÊǼǼһ¸ö ±äÁ¿±»Òý ÓÃÁ˶àÉٴΣ¬ÕâÊÇ php µÄ copy on write (дʱ¸´ÖÆ) µÄ»úÖƵÄÒ»¸öÖØÒªÌصã [2] ¡£ debug_print_backtrace ¿ÉÒÔÈÃÎÒÃDz鿴Õû¸ö³ÌÐòµÄµ÷ÓÃÕ»£¬ÓÃÀ´²é¿´Ë²¼äº¯Êýµ÷ÓÃÕ»£¬·½±ãÔÚ ³ö´íʱ²é ¿´Ö´ÐÐÉÏÏÂÎÄ:. 1. 1 var_export Óë var_dump µÄ²»Í¬: http://www.laruence.com/2008/04/03/15.html 2 ÉîÈë̽ÌÖ PHP ÖеÄÄÚ´æ¹ÜÀíÎÊÌâ: http://tech.sina.com.cn/s/2006-10-26/09151204364.shtm ÉîÈëÀí½â PHP Ô­ ÀíÖ®±äÁ¿·ÖÀë: http://www.laruence.com/2008/09/19/520.html ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 5 Ò³ ¹² 51 Ò³ A PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 ²é¿´Êä³ö£¬Ã÷È·µÄÊä³öÁËÈý¸öº¯ÊýµÄµ÷ÓÃÕ»ÐÅÏ¢£º 1.2 ´íÎó¿ØÖÆºÍ ÈÕÖ¾¼Ç¼µ÷ÊÔ 1.2.1 ´íÎóÑ¡Ïî¿ØÖÆ Php.ini ÅäÖÃÖУ¬¸ú´íÎóÏà¹ØµÄÑ¡ÏîÖ÷Òª£º error_reporting¡¢display_errors¡¢log_errors¡¢error_log µÈ¼¸¸ö£¬ ÕâЩѡÏîÔÚÒ»°ãÓï·¨¼¶±ðµÄ µ÷ÊÔÊǺÜÓаïÖúµÄ¡£ Error_reporting ÊÇÉèÖà PHP ´íÎóÏÔʾ¼¶±ð£¬PHP µÄ´íÎóÏÔʾ¼¶±ðÓÐÕâô ¼¸¸ö£º value constant 1 E_ERROR 2 E_WARNING 4 E_PARSE 8 E_NOTICE 16 E_CORE_ERROR 32 E_CORE_WARNING 64 E_COMPILE_ERROR 128 E_COMPILE_WARNING 256 E_USER_ERROR 512 E_USER_WARNING 1024 E_USER_NOTICE 6143 E_ALL 2048 E_STRICT 4096 E_RECOVERABLE_ERROR E_ALL °üº¬³ýÈ¥ E_STRICT ÒÔÍâµÄËùÓдíÎóÐÅÏ¢,Ò»°ãµÄÑ¡ÏîÊÇÏÔʾ Notice ÒÔÉϼ¶±ðµÄÏûÏ¢£¬¾ÍÊÇÉè ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 6 Ò³ ¹² 51 Ò³ PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 ÖÃΪ£º error_reporting = E_ALL & ~E_NOTICE ÕâÑù¾Í»áÏÔʾ°üÀ¨¾¯¸æ¡¢ ÖÂÃü´íÎóµÈµÈ¹Ø¼ü´íÎó£¬Ò»°ã Notic ´íÎó¾ÍÊÇ°üÀ¨±äÁ¿Î´¶¨ÒåÖ®ÀàµÄ¶¨Ò壬±È ÈçÕâÑùµÄ´úÂ룺 (Notice ´íÎóÒ»°ã²»ÊÇÌ«ÑÏÖØ£¬³ÌÐò»¹»á»á¼ÌÐøÖ´ÐÐ) Ö´ÐоͻáÌáʾ£¬Èç¹ûÉ趨ÁËÆÁ±Î Notice£¬ ¾Í²»»áÌáʾ´íÎó£º ¾¯¸æÀà´íÎóÒ»°ã¶¼ÊÇ±È Notice ¸üÑÏÖصĴíÎ󣬱ÈÈçÊý×é²»´æÔھͽøÐÐÑ­»· ÊÇ×î³£¼ûµÄ£º Ö´Ðоͻᱨһ¸ö Warning£º (Warning ´íÎóÑÏÖس̶ÈΪÖеȣ¬³ÌÐò»á¼ÌÐøÖ´ÐУ¬ µ«Êǽ¨Òé½â¾ö) ÖÂÃü´íÎóͨ³£¶¼ÊÇÓï·¨¼¶±ðµÄ´íÎ󣬱ÈÈçȱÉٷֺŽáβÖ®ÀàµÄ£º (ÖÂÃü´íÎóÔòÊÇ ³ÌÐò»áÖÕÖ¹Ö´ÐУ¬Ò»¶¨Òª½â ¾ö) ±¨´íÌáʾ£º Error_reporting ͬÑù¿ÉÒÔ×÷Ϊһ¸ö PHP º¯ÊýÀ´µ÷ Ó㺠ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 7 Ò³ ¹² 51 Ò³ Parse errer: syntax errer, unexpected Send in [Iummand line cede un line 1 PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 display_errors ÊÇÉ趨ÊÇ·ñÔÚ PHP ½Å±¾Ö´ÐÐÊä³öµÄʱºòÊä³ö´íÎóÐÅÏ¢£¬È± Ê¡ÊÇ£º Ò»°ãÔÚÏßÏ¿ª·¢µ÷ÊÔ»·¾³£¬ÎªÁ˱ãÓÚµ÷ÊÔ£¬»á´ò¿ª´íÎóÏÔʾѡÏÔÚÏßÉÏΪÁ˲»Ð¹Â¶Ãô ¸ÐÐÅÏ¢£¬Ò»°ã»á°É display_errors ÉèÖÃΪ Off¡£ ÕâÀïÓÖ´øÀ´ÁËÒ»¸öеÄÎÊÌ⣬Èç¹ûÏßÉϱ¨´í ÁË£¬ÎÒÃÇÈçºÎ²é¿´µ½´íÎó£¿ÄÇô¾ÍÐèÒª log_errors Ñ¡ÏîÁË¡£Õâ ¸öÑ¡ÏîÊÇÉ趨ÊÇ·ñ¼Ç¼´íÎóÈÕ Ö¾£¬Ò»°ãÑ¡ÏîÊÇ Off£¬µ«ÊÇÈç¹ûÊÇÔÚÏßÉϹ¤×÷»·¾³£¬½¨Òé°ÑËü´ò¿ª£º ´ò¿ªÁË log_errors Ñ¡ÏîµÄ ͬʱ£¬Ò²ÒªÉèÖôíÎóÈÕÖ¾¼Ç¼µÄĿ¼ѡÏî error_log £º ÄÇôÔÚ error_reporting µÄÉèÖ÷¶Î§ ÄÚ£¬PHP ½âÎöÏà¹ØµÄ´íÎó¾ÍÄÜÔÚÈÕÖ¾Àï¿´µ½ÁË¡£ 1.2.2 ´íÎóÅ׳öºÍ´¦Àí ´íÎóÅ׳öºÍ´¦ÀíÖ÷ ÒªÊÇ˵ÎÒÃÇÔÚ³ÌÐòÖУ¬Äܹ»×Ô¼º´¥·¢´íÎ󣬻òÕßÊÇ×Ô¼º½Ø»ñ´¦Àí´íÎó£¬ÀàËÆÓÚÃæÏò¶Ô Ïó±à³ÌÀï µÄÒì³£´¦Àí throw Å׳öÒì³££¬catch ½Ø»ñÒì³£Ò»¸ö˼·¡£ trigger_error¡¢set_error_handler¡¢set_exception_handler ÕâÈý¸ö api Ö÷Òª¾ÍÊÇ´¦Àí´íÎóÅ׳ö ºÍ´¦ÀíÄÚÖú¯Êý¡£ ʹÓà trgger_error ¿ÉÒÔ´¥·¢Ò»¸ö´íÎ󣬴¥·¢¼¶±ð¸úÉÏÎÄµÄ error_reporting µÄ É趨¼¶±ðÒ»Ö£¬Ö÷ÒªÊÇÄܹ»´¥ ·¢µÄÊÇ E_USER_ERROR, E_USER_WARNING,
  • 4. E_USER_NOTICE ÈýÖÖ¼¶±ðµÄ´íÎó£¬Èç¹û²»×ö´¦Àí£¬ÄÇô ÔÚ³ÌÐòÖ´Ðоͻᱨ´í£¬´íÎóÌáʾ¸ú ÉÏÎÄÃèÊö²î²»¶à£¬»á³öÏÖ Fatal Error¡¢Warning¡¢Notice ÈýÖÖ´íÎóÏÔʾ¡£ trigger_error ÊÇÒ»¸ö Å׳ö´íÎóµÄº¯Êý£¬¿ÉÒÔÅ׳öÈκÎÓû§¼¶±ð´íÎó£¬ÔÚ·ÇÃæÏò¶ÔÏóʱ´úµÄ±à³ÌÀ¿ÉÒÔ×÷ Ϊһ¸öÌá ʾ´íÎóµÄÒ»ÖÖ·½Ê½¡£ ʾÀý£¬ÎÒÃÇÒ»¸öº¯ÊýÐèÒªÊäÈëÒ»¸öÕûÐεıäÁ¿£¬Èç¹û²»ÊǾʹ¥·¢Ò»¸ö¾¯ ¸æ£º ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 8 Ò³ ¹² 51 Ò³ errors a , , nr errur_ 386 ; H5 stated annue, yuu're Strongly tu use errnr logging in place nF 381 ; error displaying on production web sitos. 382 errors unrecognized text Un PHP µ÷ÊÔ¼¼ÊõÊÖ²á 1.0.0 Êä³ö½á¹û£¬¿ÉÒÔ¿´µ½ÓÐÒ»¸ö¾¯¸æ²úÉúÁË£º set_error_handler ˵ÎÒÃÇ·¢Éú ÁË´íÎóµÄʱºò£¬ÓÃʲô´¦Àíº¯ÊýÀ´´¦Àí£¬Ò»°ãÕâ¸ö¶¼ÊÇÓÃÀ´Õë¶Ô trigger_error Ö®ºóÀ´½øÐдíÎó ´¦ÀíµÄ£¬Á½¸öº¯Êý½áºÏ£¬ÎÒÃÇ¿ÉÒÔ¹¹½¨Ò»¸ö¼òµ¥ÓÐЧµÄ´íÎóʶ±ðºÍ¼Ç¼µÄ¹¦ÄÜ¡£ ÎÒÃÇÏȱàдһ ¸ö´íÎó´¦Àíº¯Êý£º ÔÙ±àдһ¸ö´íÎóµ÷Ó㬲¢ÇÒÖ´ÐÐ: ºÚҹ·È˵ĿªÔ´ÊÀ½ç / ·çÑ©Ö®Óç µÚ 9 Ò³ ¹² 51 Ò³