Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 8 ■ TESTING, DEPLOYMENT, AND CONTINUOUS INTEGRATION^121

Remember that you may have separate php.ini files for both the CLI PHP binary and your
web server. An easy way to see if you have successfully installed Xdebug is as follows:

> php –v
PHP 5.?.? (cli) (built: Jul 17 2007 18:14:23)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with Xdebug v2.0.2-dev, Copyright (c) 2002-2007, by Derick Rethans

If you see with Xdebug in the PHP CLI version, confirm that it also shows up in phpinfo()
when used on your web server. You will need to restart Apache to pick up the change to the
PHP environment.

Tracing with Xdebug.


Much of the Xdebug functionality is in the form of extra debugging statements that you can use
to get extra information about your application. For example, you can find out what class, method,
or function called the current context, and from which file and line that call originated. For
example, Listing 8-8 demonstrates a simple call trace.

Listing 8-8. Using Xdebug to Trace Call Stacks

<?php
class MyClass {
public function myCaller($other) {
$other->myCallee();
}
}

class MyOther {
public function myCallee() {
printf("%s", xdebug_call_class());
printf("::%s", xdebug_call_function());
printf(" in %s", xdebug_call_file());
printf(":%s\n", xdebug_call_line());
}
}

$a = new MyClass();
$b = new MyOther();

$a->myCaller($b);

This example outputs the following:

MyClass::myCaller in /path/to/xdebug.php:4

McArthur_819-9C08.fm Page 121 Friday, February 22, 2008 9:06 AM

Free download pdf