Translate

Saturday 30 November 2013

Latest Question and Answers


1. What is the correct way to send a SMTP (Simple Mail Transfer Protocol) email using PHP?

 s.sendmail($EmailAddress, [$MessageBody], msg.as_string())
 sendmail($EmailAddress, "Subject", $MessageBody);
 mail($EmailAddress, "Subject", $MessageBody); ***********
 <a href="mailto:$EmailAddress">$MessageBody</a>


2. The built-in function to get the number of parameters passed is:

arg_num()
func_args_count()
func_num_args()  ***********
None of these


3. Which of the following will start a session?

session(start);
session();
session_start(); ***********
login_sesion();


4. Which of the following is the right MIME to use as a Content Type for JSON data?

text/x-json
text/javascript
application/json ***********
application/x-javascript


5. What is the output of the following code?

<?php
  $string1 = "abcdefg";
  $string2 = "abcfghi";
  $position = strspn($string1 ^ $string2, "\0");
  echo $position;
?>
1,2,,3,4
ans 3 ********guess


6. Which of the following is true about the singleton design pattern?

A singleton pattern means that a class will only have a single method.
A singleton pattern means that a class can have only one instance object. ***********
A singleton pattern means that a class has only a single member variable.
Singletons cannot be implemented in PHP.


7. What is the use of the @ symbol in front of a variable?

It sets the type of that variable to a string.
It sets the type of that variable to an array.
It hides any error messages coming from the expression. ***********
It has no use and would return an error.


8.Which function can be used to delete a file?

delete()
delete_file()
unlink() ***********
fdelete()
file_unlink()


9. What is the best method for sanitizing user input with PHP?

a. PHP has a specific feature named magic-quotes to sanitize everything.
b. In general there is no need to sanitize input, apart from specific situations.
c. Whenever you embed a string within foreign code, you must escape it, according to the rules of that language. E.g. for MySQL, you will use mysql_real_escape_string, for HTML you will escape it with htmlspecialchars. ***********
d. PHP exposes Regex functionalities to parse and sanitize everything.


10. <?php
var_dump (3*4);
?>

int(3*4)
int(12)*****
3*4
12
None of the above


11. Which of the following methods should be used for sending an email using the variables $to, $subject, and $body?
mail($to,$subject,$body) ***********
sendmail($to,$subject,$body)
mail(to,subject,body)
sendmail(to,subject,body)

12. What will be the output of the following code?
<?
$a = 3;
print '$a';
?>
Ans $a


13. Which of the following is the correct way to check if a session has already been started?
if ($_SERVER["session_id"]) echo 'session started';
if (session_id()) echo 'session started'; ***************************
if ($_SESSION["session_id"]) echo 'session started'; *
if ($GLOBALS["session_id"]) echo 'session started';

 note: session_id() returns the session id for the current session or the empty string ("") if there is no current session (no current session id exists) or Or maybe testing whether $_SESSION is set or not, with isset


14. Which method is used to capture the whole screen in PHP?

imagegrabscreen(); ***********
imagegrabwindow()
imagealphablending()
getimagesizefromstring()


15. What function should you use to join array elements with a glue string?
join_st
implode ***********
connect
make_array
None of these


16. What would occur if a fatal error was thrown in your PHP program?

The PHP program will stop executing at the point where the error occurred. ***********
The PHP program will show a warning message and program will continue executing.
Since PHP is a scripting language so it does not have fatal error.
Nothing will happen.

17. Which of the following cryptographic functions in PHP returns the longest hash value?
md5()
sha1() ***********
crc32()
All return the same hash value length.


18. Should assert() be used to check user input?
Yes
No****


19. Which of the following variable declarations within a class is invalid in PHP?
private $type = 'moderate';
internal $term = 3;  ***********
public $amnt = '500';
protected $name = 'Quantas Private Limited';

20. What is the correct syntax of mail() function in PHP?
mail($to,$subject,$message,$headers) ***********
mail($from,$to,$subject,$message)
mail($to,$from,$subject,$message)
mail($to,$from,$message,$headers)

21. What will be the output of the following code?
<?
echo 5 * 6 / 2 + 2 * 3;
?>

1
20
21***
23
34

22. you have defined three variables $to, $subject, and $body to send an email. Which of the following methods would you use for sending an email?
a:    mail($to, $subject,$body)*****
b:    sendmail($to, $subject,$body)
c:    mail(to, subject,body)
d:    sendmail(to, subject,body)
Answer:  mail($to, $subject,$body)


23. Which of the following would trigger the browser's "Save As" prompt?

a. header('file.txt');
header('location: file.txt');
b.

c. header('Content-type: application/txt');
header('location: file.txt');
echo "file contents";

d. header('Content-type: application/txt');                  **************************** doubt
header('Content-Disposition: attachment; filename="file.txt"');
echo "file contents";



24 What is the correct use of the constant, PHP_EOL?

For displaying a new line within an HTML document.
For writing a new line that is cross-platform compatible.****
As an 'End Of Line' character for only DOS systems.
As an 'End Of Line' character for only UNIX systems.

25.What is the correct PHP command to use to catch any error messages within the code?

set_error('set_error');
set_error_handler('error_handler');**
set_handler('set_handler');
set_exception('set_exception');


26. Which of the following is not a PHP magic constant?

__FUNCTION__
__TIME__******************
__FILE__
__NAMESPACE__
__CLASS__


27. Which of the following will print out the PHP call stack?

a. $e = new Exception;
var_dump($e->debug());
b. $e = new Exception;
var_dump($e->getTraceAsString()); *******
c. $e = new Exception;
var_dump($e->backtrace());
d. $e = new Exception;
var_dump($e->getString());


28. Which of the following methods is used to check if an array is associative or numeric?

is_Assoc().
isAssoc() *********
is_assoc()
None of the above.


29. What is the best way to load a file that contains necessary functions and classes?

include($filename); ----
require($filename);
include_once($filename);
require_once($filename);


30. Which one of the following is not an encryption method in PHP?
crypt()
md5()
sha1()
bcrypt() *****

31. Which of the following is not a valid cURL parameter in PHP?
CURLOPT_RETURNTRANSFER
CURLOPT_GET*************
CURLOPT_POST
CURLOPT_POSTFIELDS

32. Which of the following is used to maintain the value of a variable over different pages?
static
global
session_register()*****
None of these


33. what is the output of the following code?

<?php
  echo "<pre>";
  $array1 = array(
 "1"=>"a",
 "2"=>"b",
 "3"=>"c"
);
  $array = array_flip($array1);
  print_r($array);
  echo "</pre>";
?>

Ans array_flip() returns an array in flip order, i.e. keys from array become values and values from array become keys. *************

34. which of the following is true regarding the str_replace() function in PHP?

a. It requires a minimum of 2 parameters.
b. The first argument is the string or array being searched and replaced.
c. The second argument is the the replacement value that replaces found search values. ********
d. It will replace only the first matched string.

35: Which of the the following are PHP file upload related functions
Ans is_uploaded_file() and C: move_uploaded_file() **********


36. What will be the output of the following code?
<?
$a = 0x01;
$b = 0x02;
printf ("%x", ($a << $b.$b));
?>

a. 0
b. 1
c. 10000
d. 400000 ***********
e. 800000
f. Syntax error


37. What is the difference between $a == $b and $a === $b in PHP?

There is no difference.
'==' checks whether $a and $b have the same string representation, '===' checks whether the values are of the same type and $a is equal to $b.
'==' checks whether $a and $b have the same string representation, '===' checks whether $a and $b are equal after type juggling.
'==' checks whether $a and $b are equal after type juggling, '===' checks whether $a and $b are equal and are of the same type. ***********

38. Which of the following is the correct way to create two independent connections to MySQL in PHP?

a $dbh1 = mysql_connect($hostname, $username, $password);
$dbh2 = mysql_connect($hostname, $username, $password, true); *****************
b. $dbh1 = mysql_connect($hostname, $username, $password, 1);
$dbh2 = mysql_connect($hostname, $username, $password, 2);
c. $dbh1 = mysql_connect($hostname, $username, $password, +1);
$dbh2 = mysql_connect($hostname, $username, $password, -1);
d. $dbh1 = mysql_connect($hostname, $username, $password,'primary');
$dbh2 = mysql_connect($hostname, $username, $password, 'secondary');

39. Which is the best approach to parse HTML and extract structured information from it?

Use an existing LibXML based library like DOM or phpQuery.
String searching and extraction.
Use an XML parser (as simpleXML) and XPath queries if available.  ******
Use specific regular expressions.


==========================================================================================================================================================

40. Which of the following is not a valid php.ini parameter with respect to file uploading?

upload_max_filesize
allow_url_fopen  **********
upload_tmp_dir
post_max_size


41. What is the correct PHP command to use to catch any error messages within the code?

set_error('set_error');
set_error_handler('error_handler');***********
set_handler('set_handler');
set_exception('set_exception');


43. How can short tags be enabled in PHP?

Set the value of short_open_tag=on in the php.ini file and restart the web server. *************
Set the value of short_tag=on in the php.ini file and restart the web server.
Set the value of short_tags=on in the php.ini file.
None of the above.




4. What will be the output of the following code?

<?php
$str="Hello";
$test="lo";
echo substr_compare($str, $test, -strlen($test), strlen($test)) === 0;
?>


4. Which of the following is incorrect with respect to json_encode and serialize()?

Both methods are same and produces json only.
JSON converts UTF-8 characters to unicode escape sequences. serialize() does not.-----------
json_encode()  generates the JSON representation of a value while serialize() generates a storable representation of a value.
Any data encoded with json_encode() function can be used outside a PHP application whereas data generated with serialize() can only be used in a PHP application.


Which of the following type cast is not correct?

<?php
$fig = 23;
$varbl = (real) $fig;
$varb2 = (double) $fig;
$varb3 = (decimal) $fig;
$varb4 = (bool) $fig;

?>


What will be the output of the following code?

<?php
echo 30 * 5 . 7;
?>



What is a salted MD5 hashed password?

It is MD5 representation of a password.
It is doubly MD5 representation of a password.
It is MD5 representation of a random string concatenated with MD5 of a password.
There is no such thing as salted MD5.


Which of the following statements is incorrect, with regards to inheritance in PHP?

A class can only have a single parent, i.e. it cannot extend more than one class.
A class can both extend another class as well as implement an interface.
A class can implement more than one interface.
A class can extend more than one class.


How would you guarantee a reliable expiration of a PHP session after 30 minutes?

Use session.gc_maxlifetime which specifies the number of seconds after which data will be seen as 'garbage' and cleaned up. Garbage collection occurs during session start.
Use session.cookie_lifetime which specifies the lifetime of the cookie in seconds, which is then sent to the browser.
Session timeout management should be implemented manually. **********************
All PHP sessions end after 30 minutes.



Why is it not recommended to use $_REQUEST when handling form submissions in PHP?

It's difficult to determine whether it is a $_POST or $_GET request.
 $_REQUEST is deprecated.
$_REQUEST includes $_COOKIE by default, and parameters from $_COOKIE with the same name may be overriden with parameters from $_GET or $_POST. *****
$_REQUEST does not handle HTTP rquests, it handles database requests.




11. Which of the following is true with respect to database tables in PHP?----------

a. New database tables cannot be created using PHP.
b. The structure of an existing table cannot be altered using PHP.
c. An existing table cannot be dropped using PHP.
d. New database tables can be created using PHP, provided that the user connecting to the database has enough privileges. ***** guess




12. What will be the output of the following code?---------

class Person
{
    protected $name;

    public function __construct($name) {
    $this->name = $name;
    }

    public function getName() {
    return $this->name;
    }
}

$person = new Person("Foo");

echo $person->getName();

a. Nothing will be printed on-screen.
b. Foo
c. Syntax error on line $this->name=$name
d. Fatal error on line $this->name=$name



21. What is the correct PHP command for setting a MySQL connection character set to UTF8?---------------------

mysqli_client_encoding($link, "utf8"); ******* doubt
mysqli_character_set_name($link, "utf8");
mysqli_set_charset($link, "utf8");
mysql_character_set_name($link, "utf8");


18. Which of the following is incorrect with respect to separating PHP code and HTML?---------
a Use MVC design.
b As PHP is a scripting language, so HTML and PHP cannot be separated.
c Use any PHP template engine e.g: smarty to keep the view from business logic.
d Create one script containing your (PHP) logic outputting XML and one script produce the XSL to translate the XML to your views.



34. Which one of these should be avoided with respect to the database username and password in PHP?

Always store database username and password in a PHP file. ----
Store the database username and password in a configuration file outside the webroot.
The username used for connecting to the database should only have limited access to the database.
Avoid a single database user having access to multiple databases if not required.


35. Which of the following is the correct way to convert a variable from a string to an integer?

$number_variable = int_val $string_variable;
$number_variable = (int_val)$string_variable;
$number_variable = int($string_variable);
$number_variable = (int)$string_variable; --------


Q.  Best way to deploy from git
d. Copy over your .git directory to your web server On your local copy, modify your .git/config file and add your web server as a remote: On the server, replace .git/hooks/post-update with this file (mirror in so) Add execute access to the file (again, on the server):Now, just locally push to your web server and it should automatically update the working copy

Q. What is the difference between the float and double type in php
Ans.  both are same

Q. what is the best way to row count using PDO in PHP with MySQL
Ans. $nRows = $pdo->query('select count(*) from blah')->fetchColumn();
echo count($nRows);

Q:  code of copy array to another array php
Ans $arrayMerged = array_merge($arrayOne, $arrayTwo)

Q:  <?php
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}1,$3';
echo preg_replace($pattern, $replacement, $string);
?>

ans   April1,2003    http://us3.php.net/preg_replace


Q: return extension of filename in php
   common gateway cgi in php
   read an object into an array variable php





result 3.4 below average---- average PHP5 3.6--- Top30%  PHP5 3.75

Q: What will be the output of the following code?

 function fn(&$var)
 {
   $var = $var - ($var/10 * 5);
   return $var;
 }
 echo fn(100);

Q: Which of the following is a correct declaration?
a.static $varb = array(1,'val',3);
b.static $varb = 1+(2*90);
c.static $varb = sqrt(81);
d.static $varb = new Object;

Q: Which of the the following are PHP file upload related functions
Ans is_uploaded_file() and C: move_uploaded_file()

Q: What will be the output of the following code?
$var = 10;
function fn()
{
   $var = 20;
   return $var;
}
fn();
echo $var;
Ans 10

Q: Which of the following pair have non-associative equal precedence
Ans: ==,!=

Q: The inbuilt function to get the number of parameters passed is:
Ans: c: func_num_args()

Q: What is the size limit of strings in php?
Ans:  There is no limit (hardware limit) / None of the above

Q: You need to count the number of parameters given in the URL by a POST operation. The correct way is
Ans: count($_POST)

Q: Which of the following is not a file-related function in PHP
Ans: fappend

Q: Which of the following variable declarations within a class is invalid in PHP5
Ans internal $term =3;

Q: Which of the following functions output text?
Ans  a, b echo(), print()

Q: Which of the following is a Ternary Operator
Ans ?:

Q: Which of the following environment variables is used to fetch the IP address of the user in your PHP application
Ans SERVER['REMOTE_ADDR'];

Q: What does the array_combine (a, b) function do
Ans It associates all keys of a with the values of b and returns a new array

Q: You need to check the size of a file in php function.
$size=x(filename);
which function will suitably replace "x";
Ans filesize


Q: What will be the output of the following code?
<?php
Var_dump(3*4);
?>
Ans int(12)

Q: Which of the following are useful for method overloading?
Ans a.  __get, __set, __call, __callStatic

Q: which of the following is string literal definition in php
Ans all are  string literal

Q: Which of the following characters are taken care of by htmlspecialchars?
Ans All of the above

Q: In your php application you need to open a file. You want the application to issue a warning and continue execution, in case the file is not found.The ideal function to be used is:
Ans a include (include will only produce a warning (E_WARNING) and the script will continue)

Q: What function should you use to join array element with a glue string
Ans import

Q: what do you infer from the following code?
<?php
$str= "Dear Customer.\nThanks for your query.We will reply very soon?\n Regards. \n Customer Service Agence';
?>
Ans d: All will be printed on one line irrespective of the \n


Q: Which of the following variable are supported by'str_replace()' function?
Ans string, Array

Q:which of the following variable names are invalid?
a:    $var_1
b:    $var1
c:    $var-1
d:    $var/1
Answer:
c: $var-1, and d: $var/1

Q: Which of the following printing construct/function accepts multiple parameters?
a:    echo
b:    print
c:    printf
d:    All or the above
Answer:
d: echo, printf

Q: Consider the following two statements:
l    while (expr) statement
ll    while (expr): statement ... endwhile;
Which of the following are true in context of the given statements?
a:    I is correct and II is wrong
b:    I is wrong and II is correct
c:    Both I & II are wrong
d:    Both I & II are correct
Answer:  d: Both I & II are correct


Q: you have defined three variables $to, $subject, and $body to send an email. Which of the following methods would you use for sending an email?
a:    mail($to, $subject,$body)
b:    sendmail($to, $subject,$body)
c:    mail(to, subject,body)
d:    sendmail(to, subject,body)
Answer:  mail($to, $subject,$body)

Q: Which of the following is a PHP resource?
a:    Domxml document
b:    Odbc link
c:    File
d:    All of the above
Answer:
d: All of above



=====================================================================================================

Q:With the following code, will the word Hello be printed *************
<?
 //?>Hello
Ans NO

Q: What will be the output of the following code?*************
 <?php
 print null == NULL; ?>
Ans 1*(guess)

Q: What will be the output of the following code? **************
 <?
 $a = "NULL";
 echo !empty ($a);
 ?>

Q: What is the output of the following code? *************
 <?
 $a = (1 << 0);
 $b = (1 << 1);
 echo $b | $a;
 ?>


Q: <?            *************
 $a = "printf";
 $a ("hello");
 ?>
Ans fatel error

Q: <?            *************
 $a = "print";
 $a ("hello");
 ?>
Ans  fatal error  *************


Q: What will be the result of following operation?*************
print 4<< 5;
128


Q: <?php                        *************
 $a = (1 << 0);
 $b = (1 << $a);
 $c = (1 << $b);
 echo ($c || $b) << 2 * $a | $a;
 ?>
Ans

Q: what will be the output of the folowing code?*************
<?
echo"5.0"=="5";
?>
Ans

Q: What is the output of the following code?*************
<?php echo 0x0500; ?>
Ans


Q: What will be the output of the following code?*************
<?
echo 5*6/2+2*3;
?>
Ans 1, 20, 21*, 23, 34

Q: what will be the output of the following code?*************
<? echo false ?>
Ans 0, false*, FALSE, Nothing, Syntax error


Q: What will be the output of the following code?*************
<?php
$s="Hello Word";
print $s[4];
 ?>
Ans H, e, l*, o, ""(a space)
============================================================================================================

Q: <?
 echo 0500, 0505;
 ?>
Ans  320,325   (description it is a Octal To Decimal Conversion 500= 5*8^2 +0*8^1 +0*8^0=320...  http://www.statman.info/conversions/octal.html)

Q: <?
 echo !!!0;
 ?>
Ans 1

Q:What will be the output of the following code?

<?

$a = 0x01;
$b = 0x02;

printf ("%x", ($a << $b.$b));

?>

0
1
10000
400000
800000
 Syntax error

2 comments:

  1. The Casino Site – Live Casino Review - LuckyClub
    The Casino site is luckyclub.live a new addition to the gambling industry and one that was initially conceived by a gambling company, LuckyClub. We review all of the

    ReplyDelete
  2. The Star Casino at The Star Gold Coast - JTG Hub
    Discover a world of 출장샵 luxury at The Star Gold Coast. 광명 출장샵 Featuring a wide variety of restaurants, a 24/7 casino, 보령 출장안마 live entertainment 파주 출장샵 and a 24/7 poker 계룡 출장마사지 room.

    ReplyDelete