Guide for Xdebug Installation on Mac OS X

Xdebug安装与使用
本文介绍了Xdebug的安装过程及基本使用方法。通过PECL安装Xdebug,并在php.ini中正确配置zend_extension路径。文章还展示了如何利用Xdebug增强版的var_dump()函数和xdebug_debug_zval()函数进行变量调试。

Installation:

PECL Installation

As of Xdebug 0.9.0 you can install Xdebug through PEAR/PECL. This only works with with PEAR version 0.9.1-dev or higher and some UNIX. And of course on Mac.

Installing with PEAR/PECL is as easy as:



 

but you still need to add the correct line to your php.ini: (don't forget to change the path and filename to the correct one — but make sure you use the full path)



Don't forget to restart Apache.

Note: You should ignore any prompts to add "extension=xdebug.so" to php.ini — this will cause problems.

To verify if you have Xdebug loaded on your machine.

Create a file to run phpinfo().

You would see something like this:



In the case you use "extension=xdebug.so", you will get a warning message in phpinfo().



Here we go. More installation methods, please visit Xdebug documentation .

------------------------------------------------------------------------------------------------------------

Basic Features

It says Xdebug replaces PHP's var_dump() function for displaying variables. Xdebug's version includes different colors for different types and places limits on the amount of array elements/object properties, maximum depth and string lengths in the document.

Let's try the popular function var_dump() we use for debug.





Wow... very ugly, nothing different on my page, where are the colors?

Don't worry, check this:

By default Xdebug overloads var_dump() with its own improved version for displaying variables when the html_errors php.ini setting is set to 1. In case you do not want that, you can set this setting to 0, but check first if it's not smarter to turn off html_errors.

AHa, it's html_errors setting in php.ini. You could either change it in php.ini (restart Apache) or just add a line in your codes.


Let's check this time:



Looks better now :)

Let's try this function void xdebug_debug_zval( [string varname [, ...]] ). This function displays structured information about one or more variables that includes its type, value and refcount information. Arrays are explored recursively with values. This function is implemented differently from PHP's debug_zval_dump() function in order to work around the problems that that function has because the variable itself is actually passed to the function.





Pretty clear. No need to explain I think :) Wait, how about errors? Let's leave the function blank.





No error shows? Is is the php setting again? Let's have a try.





There we go. Looks cool and more understandable, isn't it?

Conclusion

1.    Use full path when you edit zend_extension in php.ini ;
2.    Turn on display_errors and html_errors in php.ini when debug mode.

Above all, some simple instructions for installation and basic usages. Please feel free to leave comments or email me if you have any question or find mistake in the article. Please visit the Xdebug site for more information.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值