20 May 2012

PHP Interview Questions - IV

 

How can we know the count/number of elements of an array?

                2 ways:
a) sizeof($array) - This function is an alias of count()
b) count($array) - This function returns the number of elements in an array.
Interestingly if you just pass a simple var instead of an array, count() will return 1. 


How many ways we can pass the variable through the navigation between the pages?

                At least 4 ways:

1. Put the variable into session in the first page, and get it back from session in the next page.

2. Put the variable into cookie in the first page, and get it back from the cookie in the next page.
3. Put the variable into a hidden form field, and get it back from the form in the next page.
4. can pass the variabe as querystring with the help of question mark

Will comparison of string "10" and integer 11 work in PHP?

               Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.

If we login more than one browser windows at the same time with same user and after that we close one window, then is the session is exist to other windows or not? And if yes then why? If no then why?

             Session depends on browser. If browser is closed then session is lost. The session data will be deleted after session time out. If connection is lost and you recreate connection, then session will continue in the browser. that means when you close a browser the other browser also lost the session values because session variables are stored in server.

What is the difference between PHP4 and PHP5?

            = PHP4 cannot support oops concepts and Zend engine 1 is used.
           = PHP5 supports oops concepts and Zend engine 2 is used.

           = Error supporting is increased in PHP5.
           = XML and SQLLite will is increased in PHP5.

What is meant by nl2br()?

            nl2br() inserts a HTML tag <br> before all new line characters \n in a string.
that is
echo nl2br("god bless \n you");
output:
god bless<br>
you

How can we increase the execution time of a php script?

            By the use of void set_time_limit(int seconds)
Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.


How can we get second of the current time using date function?

            $second = date("s"); 

What is the maximum size of a file that can be uploaded using PHP and how can we change this?

            You can change maximum size of a file set upload_max_filesize variable in php.ini file.default 2MB

What are the difference between abstract class and interface?

           Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.

          Interface: Interfaces are one type of class where all the methods are abstract. That means all the methods only declared but not defined. All the methods must be define by its implemented class.

 


 






 

No comments:

Post a Comment