| 1 comments ]

7.
How do you debug a PHP application?

This isn't something I do often, as it is a pain in the butt to setup in Linux and I have tried numerous debuggers. However, I will point out one that has been getting quite a bit of attention lately.

PHP - Advanced PHP Debugger or PHP-APD. First you have to install it by running:
pear install apd

Once installed, start the trace by placing the following code at the beginning of your script:
apd_set_pprof_trace();

Then once you have executed your script, look at the log in apd.dumpdir.
You can even use the pprofp command to format the data as in:
pprofp -R /tmp/pprof.22141.0

For more information see http://us.php.net/manual/en/ref.apd.php
8.
What does === do? What’s an example of something that will give true for ‘==’, but not ‘===’?

The === operator is used for functions that can return a Boolean false and that may also return a non-Boolean value which evaluates to false. Such functions would be strpos and strrpos.

I am having a hard time with the second portion, as I am able to come up with scenarios where '==' will be false and '===' would come out true, but it's hard to think of the opposite. So here is the example I came up with:
PLAIN TEXT
PHP:
1.
if (strpos("abc", "a") == true)
2.
{
3.
// this does not get hit, since "a" is in the 0 index position, it returns false.
4.
}
5.
6.
if (strpos("abc", "a") === true)
7.
{
8.
// this does get hit as the === ensures this is treated as non-boolean.
9.
}

9.
How would you declare a class named “myclass” with no methods or properties?
PLAIN TEXT
PHP:
1.
class myclass
2.
{
3.
}

10.
How would you create an object, which is an instance of “myclass”?
PLAIN TEXT
PHP:
1.
$obj = new myclass();

It doesn't get any easier than this.
11.
How do you access and set properties of a class from within the class?

You use the $this->PropertyName syntax.
PLAIN TEXT
PHP:
1.
class myclass
2.
{
3.
private $propertyName;
4.
5.
public function __construct()
6.
{
7.
$this->propertyName = "value";
8.
}
9.
}


12.
What is the difference between include, include_once? and require?

All three allow the script to include another file, be it internal or external depending on if allow_url_fopen is enabled. However, they do have slight differences, which are denoted below.
1. include()
The include() function allows you to include a file multiple times within your application and if the file does not exist it will throw a Warning and continue on with your PHP script.
2. include_once()
include_once() is like include() except as the name suggests, it will only include the file once during the script execution.
3. require()
Like include(), you can request to require a file multiple times, however, if the file does not exist it will throw a Warning that will result in a Fatal Error stopping the PHP script execution.

1 comments

Unknown said... @ Monday, August 3, 2009 at 8:43:00 AM GMT+1
This comment has been removed by a blog administrator.

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.