| 0 comments ]

Q14.What does function `eval` do?
Ans: Evaluate a string as PHP code;
Eg. eval('echo "This would be printed"');


Q15.What is the method by which PHP converts datatype of a given variable.
Ans: settype()
$a = "10"; // $a is string
settype($a,"integer"); // $a is integer


Q.Can we change php.ini settings at the runtime, and how?
Ans : Yes, using ini_set();


Q16.What is the difference between sort(), assort() and ksort? Under what circumstances would you use each of these?
Ans: Sorts an array, sorts an array and maintains index association, Sorts an array by key
Simple sort (sorts on values)
Simple sort after sorting the array (lets assume size of array is 10) rearranges the index, if we want to access element at index[5], using a simple sort an element value would have changed, but in assort the value is still held by index 5 though its position in the array may be 10th.
Ksort – sorts the array by key and maintains the key to data correlations

Q17.What is the difference between foo() & @foo()?
Ans: if an error occurs calling foo() would show up the error on the screen, whereas, @foo() would suppress the error because ‘@’ is a error control operator.


Q18.What is the difference between mysql_fetch_row() and mysql_fetch_array() and mysql_fetch_object?
Ans: mysql_fetch_row() – fetches a row as an enumerated array
mysql_fetch_array() - Fetch a result row as an associative array, a numeric array, or both
mysql_fetch_object - Fetch a result row as an object


Q19.What is the difference between include & include_once? include & require?
Ans: include_once includes the script only once if it is already included in the execution of the script
Include includes the script everytime the include is encountered in the code
Require is identical to include except that it results in fatal error when file is not present in the include_path.


Q20.What type of inheritance PHP supports?
Ans: An object can inherit only from one base class. Multiple inheritance is not supported in PHP.


Q21.How can we call an object's method by using the variable functions?
Ans: If MyClass contains function myFunction()


$foo = new MyClass();
$var = "myFunction";
$c->$var();

[ Resource Link : http://in.php.net/manual/en/functions.variable-functions.php ]

Ajax, Cross site scripting (JavaScript).

Q22.What is the use of AJAX?
Ans: If a page contains form that needs to be updated constantly based on runtime values, a javascript code constantly sends user input to the system and displays the results from the server, without refreshing the whole page.

Q23.What is cross site scripting, and how to avoid it?
Ans: Injecting a javascript code in the response of a form that is capable of calling and executing scripts from other site.

Occurs when variables holding form values are not cleaned with html code escaping functions.

Clean the variables before storing or before display. Recommendation is to display the code clean and store the value as it is, unless its specified otherwise.

0 comments

Post a Comment

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