Wednesday, October 19, 2011

What is a common error caused with header function?

headers already sent output started at some x line is the error. This error occurs when there is an out put generated before the header function.

How do you know whether the headers are sent or not?

We have a function headers_sent(). This function is used to check whether the headers are already sent.

What is the difference between method get and method post?

The first difference is, method get is faster in performance than post. Because, by using post method the data posted is encrypted to cipher data and sent to the server. Where in get the encryption does not happens and it is faster.
    Get method can carry limited amount of data and it is less than post method.
    Post method is secure than get as the data submitted is not visible to the real world. Where as in the get method some one may see the data submitted in the URL bar.
    Using post method We can submit the data to the server only with the help of an HTML form. Where as a get method can send the data to server with a form and also with a HTML hyperlink.

What is difference between include() function and require() function?

Both the functions are used to include a PHP file in other PHP file. Generally if we have a block of source code usefull in multiple instances, then we place the block of source code in one file and will include the file in other files. The difference between include() and require() function are as follows:
    (i) If the file path mentioned with the include function is not found then it shows a warning message and continues the execution of the script. Where as require function results a fatal error and stops the execution of the script.
    (ii) The second difference is include function is faster in execution than require function. Because with the require function the parser will check whether the file exists or not. Where as the include function does not bothere about the file is there or not.

Monday, October 10, 2011

How many types of comments are there in PHP?

There are two types of comments in PHP. They are
  1. One Line comments (// or #)
  2. Multiple Line comments (/* */)
The "one-line" comment styles only comment to the end of the line or the current block of PHP code, whichever comes first.
Eg:
      
     <?
      // echo 'Your code upto end of the line'; 
     ?>
     <?
     # echo 'Your code upto end of the line';  
     ?> 

Multiple Line comments (/* */) are used to comment a large block of PHP code.
Ex: <?
 /*
    echo 'This is a test';
    echo 'This is a test line2';
       echo 'This is a test line 3';
 */
?>





Wednesday, October 5, 2011

What is the difference between displaying a string in single quotes and double quotes in PHP?

1) With Single Quotes the performance is faster than double quotes because the PHP parser does not checks for any variables or special characters. Whatever is there it will display that.
2) With double quotes the parser will search for the variables embedded in the string.
3) Performance wise it is always better to use single quotes. And we can use the concatenation between the strings and the variables.
4) Double quotes recognizes the new line charactes like '\n','\t' etc.., where as single quotes does not.

Top 10 PHP MVC frameworks

A good framework is easy to learn, simple to use, intuitive to work with, easy to extend or to modify, rapid to build (maintain) applications with and of course stable.

Having said that, here is my top 10 PHP MVC Frameworks:

10- Ambivalence: A Java-Maverick Port
9- WACT: Web Application Component Toolkit
8- Achievo: A good RAD framework
7- Phrame: A Java-Struts port
6- Studs: A Java-Struts port to PHP
5- Prado: The winner of Zend coding contest
4- PHPOnTrax: a Rails port - PHP5 Only
3- CakePHP: Inspired by Rails PHP4/5
2- Mojavi: The first MVC framework I fell in love with

and the winner is:

1- Symfony: Based on Mojavi and inspired by Rails

This list is based on my personal tests and use. I have tested and played with many others, but I think these are the best frameworks out there.
- The first framework I fell in love with was Mojavi because of its elegant way to implement the MVC model.
- Symfony corrected some problems in Mojavi and improved it by taking the good sides of RubyOnRails and Propel.
- CakePHP is very promising, the only problem - really, I don't know if it is a problem - is: the development process is very slow.