Answers:
- Use mysql_query() and variables: for example: $input = $_POST[‘user_input’]; mysql_query(“INSERT INTO table (column) VALUES (‘” . $input . “‘)”);
- Use PDO prepared statements and parameterized queries: for example: $input= $_POST[“user-input”] $stmt = $pdo->prepare(‘INSERT INTO table (column) VALUES (“:input”); $stmt->execute(array(‘:input’ => $input));
- Use mysql_query() and string escaped variables: for example: $input= $_POST[“user-input”] $input_safe = mysql_real_escape_string($input); mysql_query(“INSERT INTO table (column) VALUES (‘” . $input. “‘)”);
- Use mysql_query() and variables with a blacklisting check: for example: $blacklist = array(“DROP”,”INSERT”,”DELETE”); $input= $_POST[“user-input”] if (!$array_search($blacklist))) mysql_query(“INSERT INTO table (column) VALUES (‘” . $input. “‘)”);
Answers:
- mail($to,$subject,$body)
- sendmail($to,$subject,$body)
- mail(to,subject,body)
- sendmail(to,subject,body)
Answers:
- static
- global
- session_register()
- None of these
Answers:
- function_exists()
- has_function()
- $a = “function to check”; if ($a ()) // then function exists
- None of these
Answers:
- fclose
- fopen
- fwrite
- fgets
- fappend
Answers:
- 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.
Answers:
- <
- >
- single quote
- double quote
- &
- All of these
Answers:
- $array_variable = get_object_vars($object);
- $array_variable = (array)$object;
- $array_variable = array $object;
- $array_variable = get_object_vars $object;
Answers:
- private $type = ‘moderate’;
- internal $term = 3;
- public $amnt = ‘500’;
- protected $name = ‘Quantas Private Limited’;
Answers:
- __FUNCTION__
- __TIME__
- __FILE__
- __NAMESPACE__
- __CLASS__
Answers:
- $e = new Exception; var_dump($e->debug());
- $e = new Exception; var_dump($e->getTraceAsString());
- $e = new Exception; var_dump($e->backtrace());
- $e = new Exception; var_dump($e->getString());
<?php
var_dump (3*4);
?>
Answers:
- int(3*4)
- int(12)
- 3*4
- 12
- None of the above
Answers:
- Mysqli provides the procedural way to access the database while PDO provides the object oriented way.
- Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS.
- MySQLi prevents SQL Injection whereas PDO does not.
- MySQLi is used to create prepared statements whereas PDO is not.
Answers:
- s.sendmail($EmailAddress, [$MessageBody], msg.as_string())
- sendmail($EmailAddress, “Subject”, $MessageBody);
- mail($EmailAddress, “Subject”, $MessageBody);
- <a href=”mailto:$EmailAddress”>$MessageBody</a>
Answers:
- session(start);
- session();
- session_start();
- login_sesion();
<?php
function Expenses()
{
function Salary()
{
}
function Loan()
{
function Balance()
{
}
}
}
?>
Which of the following sequence will run successfully?
Answers:
- Expenses();Salary();Loan();Balance();
- Salary();Expenses();Loan();Balance();
- Expenses();Salary();Balance();Loan();
- Balance();Loan();Salary();Expenses();
Answers:
- multipart/form-data
- multipart
- file
- application/octect-stream
- None of these
Answers:
- Use an MVC design pattern.
- As PHP is a scripting language, HTML and PHP cannot be separated.
- Use any PHP template engine e.g: smarty to keep the presentation separate from business logic.
- Create one script containing your (PHP) logic outputting XML and one script produce the XSL to translate the XML to views.
Answers:
- crypt()
- md5()
- sha1()
- bcrypt()
Answers:
- join_st
- implode
- connect
- make_array
- None of these
Answers:
- delete()
- delete_file()
- unlink()
- fdelete()
- file_unlink()
Answers:
- +
- ||
- .
- |||
- None of these
Answers:
- __call,__get,__set
- _get,_set,_load
- __get,__set,__load
- __overload
Answers:
- setcookie(“OrderCookie”,34);
- makeCookie(“OrderCookie”,34);
- Cookie(“OrderCookie”,34);
- OrderCookie(34);
Answers:
- 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.
Answers:
- memory_limit = 128M
- limit_memory = 128M
- memory_limit: 128M
- limit_memory: 128M
Answers:
- $arr[$newkey] = $oldkey; unset($arr[$oldkey]);
- $arr[$newkey] = $arr[$oldkey]; unset($arr[$oldkey]);
- $newkey = $arr[$oldkey]; unset($arr[$oldkey]);
- $arr[$newkey] = $oldkey.GetValue(); unset($arr[$oldkey]);
<?
echo 5 * 6 / 2 + 2 * 3;
?>
Answers:
- 1
- 20
- 21
- 23
- 34
Answers:
- Yes
- No
Answers:
- Data can be posted using only the POST method.
- Data can be posted using only the GET method.
- Data can be posted using both GET and POST methods.
- Data cannot be posted using cURL.
Answers:
- if (session_id()) echo ‘session started’;
- if ($_SESSION[«session_id»]) echo ‘session started’;
- if ($GLOBALS[«session_id»]) echo ‘session started’;
- if ($_SERVER[«session_id»]) echo ‘session started’;
$array = array(0 => ‘blue’, 1 => ‘red’, 2 => ‘green’, 3 => ‘red’);
Which one of the following will print 2?
Answers:
- echo array_search(‘green’, $array);
- echo array_key_exists(2, $array);
- echo in_array(‘green’, $array);
- echo array_search(‘red’,$array);
echo 0x500;
?>
Answers:
- 500
- 0x500
- 0500
- 1280
- 320
Answers:
- ^[^@ ]+@[^@ ]+\.[^@ ]+$
- ^[^@ ]+@[^@ ]+.[^@ ]+$
- $[^@ ]+@[^@ ]+\.[^@ ]+^
- $[^@ ]+@[^@ ]+.[^@ ]+^
Answers:
- loadXMLFile()
- loadHTML()
- loadXML()
- loadHTMLFile()
Answers:
- array_splice()
- array_merge() and array_slice()
- PHP does not have any built-in function that can do this: the source
array will have to be copied, and $item inserted in to the required
position:
$n = 0;
foreach ($array as $key => $val) {
if ($n == $position) {
$target[] = $item;
}
++$n;
$target[$key] = $val;
} - array_insert()
$array = array(array(141,151,161), 2, 3, array(101, 202, 303));
Which of the following will display all values in the array?
Answers:
- function DisplayArray($array) {
foreach ($array as $value) {
if (array_valid($value)) {
DisplayArray($value);
} else {
echo $value. “ ”;
}
}
}
DisplayArray($array); - function DisplayArray($array) {
for ($array as $value) {
if (valid_array($value)) {
DisplayArray($value);
} else {
echo $value. “ ”;
}
}
}
DisplayArray($array); - function DisplayArray($array) {
for ($array as $value) {
if (is_array($value)) {
DisplayArray($value);
} else {
echo $value. “ ”;
}
}
}
DisplayArray($array); - function DisplayArray($array) {
foreach ($array as $value) {
if (is_array($value)) {
DisplayArray($value);
} else {
echo $value “ ”;
}
}
}
DisplayArray($array);
Answers:
- 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.
Answers:
- local
- global
- static
- None of these
Answers:
- . It is not possible.
- You should have two copies on your server. A bare copy, that you can push/pull from, to which you would push your changes to when you are done. Then you would clone this into your web directory and set up a cronjob to update git pull from your web directory every day or couple of days.
- Developing from scratch a custom deployment script to manage all the aspects.
- 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 an existing script to
process the rest of the workflow.
Make the script executable.
Answers:
- ASCII
- UTF-8
- UTF-16
- Implementation dependent
- None of the above
Answers:
- r+
- w+
- a()
- x
Answers:
- Adding a member variable that gets incremented in the default constructor and decremented in the destructor.
- This cannot be accomplished since the creation of objects is being done dynamically via «new.»
- Add a static member variable that gets incremented in each constructor and decremented in the destructor.
- Adding a local variable that gets incremented in each constructor and decremented in the destructor.
<?php
function abc()
{
return __FUNCTION__;
}
function xyz()
{
return abc();
}
echo xyz();
?>
Answers:
- abc
- __FUNCTION__
- xyz
Answers:
- +
- instanceof
- new
- =
- none of above
Answers:
- array_remove_first_element
- array_shift
- array_ltrim
- a[0] = nil
- None of these
Note: There may be more than one right answer.
Answers:
- echo()
- print()
- println()
- display()
Answers:
- include($filename);
- require($filename);
- include_once($filename);
- require_once($filename);
Answers:
- Abstract classes are not available in PHP.
- A class with a single abstract method must be declared abstract.
- An abstract class can contain non-abstract methods.
- An abstract method must have a method definition and can have optional empty braces following it.
<?php
function
vec_add (&$a, $b)
{
$a[‘x’] += $b[‘x’];
$a[‘y’] += $b[‘y’];
$a[‘z’] += $b[‘z’];
}
$a = array (x => 3, y => 2, z => 5);
$b = array (x => 9, y => 3, z => -7);
vec_add (&$a, $b);
print_r ($a);
?>
Answers:
- Array
(
[x] => 9
[y] => 3
[z] => -7
) - Array
(
[x] => 3
[y] => 2
[z] => 5
) - Array
(
[x] => 12
[y] => 5
[z] => -2
) - Error
- None of these
Answers:
- FALSE
- 0
- «0»
- «FALSE»
- 4
- -4
- null
Answers:
- header(«Content-type: text/csv»);
header(«Content-Disposition: attachment; filename=file.csv»);
header(«Pragma: no-cache»);
header(«Expires: 0»); - header(‘Content-Type: application/download’);
header(«Content-Disposition: attachment; filename=file.csv»);
header(«Pragma: no-cache»);
header(«Expires: 0»); - header(‘Content-Type: application/csv’);
header(«Content-Disposition: attachment; filename=file.csv»);
header(«Pragma: no-cache»);
header(«Expires: 0»); - header(‘Content-Type: application/octet-stream’);
header(«Content-Disposition: attachment; filename=file.csv»);
header(«Pragma: no-cache»);
header(«Expires: 0»);
<?php
echo «<pre>»;
$array = array(«red»,»green»,»blue»);
$last_key = end(array_keys($array));
foreach ($array as $key => $value) {
if ($key == $last_key) {
echo «a<br>»;
} else {
echo «b<br>»;
}
}
?>
Answers:
- b
a
b - b
a
a - b
a
a - b
b
b
Answers:
- The $this variable can be used inside any static method.
- Static properties may only be initialized using a literal or a constant.
- A property declared as static can not be accessed with an instantiated class object.
- A static variable or method can be accessed without requiring instantiation of the class.
Answers:
- A function
- A language construct
- A variable
- A reference
- None of these
Answers:
- CURLOPT_RETURNTRANSFER
- CURLOPT_GET
- CURLOPT_POST
- CURLOPT_POSTFIELDS
<?
$a = 0;
echo ~$a;
?>
Answers:
- -1
- 0
- 1
- 10
- Syntax error
Answers:
- «==» compares keys while «===» compares keys and values.
- «===» also compares the order and types of the objects.
- «===» compares the array references.
- «===» They are identical.
- None of these
Answers:
- upload_file()
- is_uploaded_file()
- move_uploaded_file()
- None of these
Answers:
- trigger_print_error()
- trigger_error()
- debug_backtrace()
- debug_print_backtrace()
<?php echo 30 * 5 . 7; ?>
Answers:
- 150.7
- 1507
- Integers can’t be concatenated.
- An error will be thrown.
Answers:
- simplexml_import_dom()
- simplexml_import_sax()
- simplexml_load_string()
Answers:
- $IP_ADDR
- $REMOTE_ADDR_USER
- $REMOTE_ADDR
- $IP_ADDR_USER
- class Insurance
- {
- function clsName()
- {
- echo get_class($this);
- }
- }
- $cl = new Insurance();
- $cl->clsName();
- Insurance::clsName();
Answers:
- Line 8 and 9
- Line 10
- Line 9 and 10
- All the three lines 8,9, and 10 should be left as it is.
Answers:
- mail($from,$to,$subject,$message)
- mail($to,$subject,$message,$headers)
- mail($from,$to,$subject,$message)
- mail($to,$from,$subject,$message)
- mail($to,$from,$message,$headers).
$array = array(0 => ‘blue’, 1 => ‘red’, 2 => ‘green’, 3 => ‘red’);
Which one of the following will print 2?
Answers:
- echo array_search(‘green’, $array);
- echo in_array(‘green’, $array);
- echo array_key_exists(2, $array);
- echo array_search(‘red’,$array);
$size=X(filename);
Answers:
- size
- filesize
- sizeofFile
- getSize
Answers:
- date(“Y-m-d H:i:s”)
- date(“y-m-d H:i:s”)
- date(“f, j Y H:i:s”)
- date(“F, j Y H:i:s”)
Answers:
- var_dump()
- fprintf()
- print_r()
- var_export()
Answers:
- die() is an alias for exit().
- exit() is a function, die() is a language construct and cannot be called using variable functions.
- die() accepts a string as its optional parameter which is printed before the application terminates; exit() accepts an integer as its optional parameter which is passed to the operating system as the exit code.
- die() terminates the script immediately, exit() calls shutdown functions and object destructors first.
Answers:
- Yes
- No
Answers:
- Adding a member variable that gets incremented in the default constructor and decremented in the destructor.
- Adding a local variable that gets incremented in each constructor and decremented in the destructor.
- Add a static member variable that gets incremented in each constructor and decremented in the destructor.
- This cannot be accomplished since the creation of objects is being done dynamically via “new.”
Answers:
- text/x-json
- text/javascript
- application/json
- application/x-javascript
<?php
$arr = array(«foo»,
«bar»,
«baz»);
for ($i = 0; $i < count($arr); $i++) {
$item = $arr[$i];
}
echo «<pre>»;
print_r($item);
echo «</pre>»;
?>
Answers:
- Array ( [0] => foo [1] => bar [2] => baz )
- foot
- bar
- baz
Answers:
- 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’;
Answers:
- set_error(‘set_error’);
- set_error_handler(‘error_handler’);
- set_handler(‘set_handler’);
- set_exception(‘set_exception’);
Answers:
- set_error(‘set_error’);
- set_error_handler(‘error_handler’);
- set_handler(‘set_handler’);
- set_exception(‘set_exception’);
<?php
curl_setopt($ch, CURLOPT_URL, «http://www.example.com/»);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>
Answers:
- There is nothing wrong with the code.
- The cURL resource $ch has not been created using the curl_init() method.
- The $ch variable needs to be initialized as $ch=null;.
- The code will cause a parse error.
Answers:
- ASCII
- UTF-8
- UTF-16
- Implementation dependent
- None of these
Answers:
- PDO
- watch
- breakpoints
- call stack
Answers:
- TRUE
- __FILE__
- FALSE
- NULL
- CONSTANT
<?php
$str=»Hello»;
$test=»lo»;
echo substr_compare($str, $test, -strlen($test), strlen($test)) === 0;
?>
Answers:
- Syntax error
- 1
- FALSE
- 0
<?
//?>Hello
Answers:
- Yes
- No
Note: There may be more than one right answer.
Answers:
- Multiple Inheritance
- Embedded Database with SQLite
- Exceptions and Iterators
- Interoperable XML Tools
I : while (expr) statement
II : while (expr): statement … endwhile;
Answers:
- I is correct and II is wrong.
- I is wrong and II is correct.
- Both I and II are wrong.
- Both I and II are wrong.
<?php
$fig = 23;
$varb1 = (real) $fig;
$varb2 = (double) $fig;
$varb3 = (decimal) $fig;
$varb4 = (bool) $fig;
?>
Answers:
- real
- double
- decimal
- boolean
Note: There may be more than one right answer.
Answers:
- echo
- printf
- All of these
Answers:
- cURL can be used to send plain text data to a remote server.
- cURL can be used to send both text as well as files using a single request.
- cURL can be used to send files to a remote server.
- Files cannot be sent using cURL.
Answers:
- md5()
- sha1()
- crc32()
- All return the same hash value length.
Answers:
- a.libxml_clear_errors()
- b.libXMLError()
- c.libxml_get_errors()
- d.libxml_use_internal_errors()
Answers:
- a. is_numeric(«200»)
- b. is_numeric(«20,0»)
- c. is_numeric(«$200»)
- d. is_numeric(«.25e4»)
- None
Answers:
- In PHP, the predefined $_POST variable is used to collect values in a form with method=«post»
- In PHP, the predefined $_GET variable is used to collect values in a form with method=«get»
- In PHP, the predefined $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE.
- Information sent from a form with the POST method is invisible to others and has an 8MB limit on the amount of information to send, which cannot be changed.
<?php
$array = array(«1″,»2″,»3″,»4»);
$variable = end(array_keys($array));
echo $variable;
?>
Answers:
- 1
- 2
- 3
- 4
Answers:
- upload_max_filesize
- allow_url_fopen
- upload_tmp_dir
- post_max_size
Answers:
- xdebug.var_display_max_depth
- xdebug.var_display_max_children
- xdebug.var_display_max_data
- xdebug.trace
<?php
echo 0x500;
?>
Answers:
- 500
- 0x500
- 0500
- 1280
- 320
Answers:
- It is used to define a new variable.
- It creates and allocates memory for a new object
- It is used to call the constructor
- The “new” operator does not exist in PHP
<?
$a = 0;
echo ~$a;
?>
Answers:
- -1
- 0
- 1
- 10
- Syntax error
<?
//?>Hello
Answers:
- yes
- no
Note: There may be more than one right answer.
Answers:
- Multiple Inheritance
- Embedded Database with SQLite
- Exceptions and Iterators
- Interoperable XML Tools
Answers:
- stdClass is php’s generic base class, kind of like Object in Java or object in Python
- stdClass is a generic ’empty’ class that’s used when casting other types to objects
- stdClass is a C++ construct used in the std:: libraries
- stdClass the base class which must be used to create anonymous classes.
Answers:
- resource
- null
- boolean
- string
- All of these
Answers:
- Integer
- String
- boolean
- Array
Answers:
- is_Assoc().
- isAssoc().
- is_assoc()
- None of the above.
Answers:
- 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.
Answers:
- $number_variable = int_val $string_variable;
- $number_variable = (int_val)$string_variable;
- $number_variable = int($string_variable);
- $number_variable = (int)$string_variable;
Answers:
- $x,$y,$z = array(7,8,9);
- ($x,$y,$z) = array(7,8,9);
- array($x,$y,$z) = array(7,8,9);
- list($x,$y,$z) = array(7,8,9);
Answers:
- text/html
- text/plain
- application/mixed
- multipart/mixed
Answers:
- Cookie Data
- referrer
- User Agent
- Session data
Answers:
- <empty output>
- A
- B
- AB
Answers:
- apache_getenv(«HTTP_HOST»)
- $_SERVER[‘HTTP_HOST’]
- $_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];
- $_SERVER[‘REQUEST_URI’];
Answers:
- The foreach construct provides an easy way to iterate over arrays.
- foreach works only on arrays and objects.
- foreach loop can be used with a variable of any type.
- foreach does not support the ability to suppress error messages using ‘@’.
<?php
function y($v) {
echo $v;
}
$w = «y»;
$w(«z»);
$w = «x»;
?>
Answers:
- x
- y
- z
- <error>
Answers:
- Interfaces can extend more than one interface
- Interfaces can extend only one interface
- Interfaces can inherit a method from different interfaces
- Interfaces can re-declare inherited methods
Answers:
- It requires a minimum of 2 parameters.
- The first argument is the string or array being searched and replaced.
- The second argument is the the replacement value that replaces found search values.
- It will replace only the first matched string.
Answers:
- <script>
var name = «<?php echo $name;?>»;
</script> - <script>
var name =<?php echo $name;?>;
</script> - <script>
var name = <?php echo json_encode($name);?>;
</script> - <script>
var name = «<?php echo addslashes($name);?>»;
</script>
Answers:
- PHP does not provide such an API.
- It sets multiple options for a cURL transfer.
- It executes the curl command.
- It sets one option for a cURL transfer.
Answers:
- $myDateTime = DateTime::createFromFormat(‘Y-m-d’, $dateString);
$newDateString = $myDateTime->format(‘m/d/Y’); - $old_date = date(‘l, F d y h:i:s’);
$old_date_timestamp = strtotime($old_date);
$new_date = date(‘Y-m-d H:i:s’, $old_date_timestamp); - implode(‘-‘, array_reverse(explode(‘-‘, $date)));
- $old_date = date(‘y-m-d-h-i-s’);
preg_match_all(‘/(\.+)-(\d+)-(\w+)-(\d+)-(\w+)-(\w+)/’, $old_date, $out);
$out = $out[0];
$time = mktime($out[4], $out[5], $out[6], $out[2], $out[3], $out[1]);
$new_date = date(‘Y-m-d H:i:s’, $time);
Answers:
- The message
- The subject
- The header
- The recipient
Answers:
- <?php
Function RandomString()
{
$characters = ’0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$randstring = »;
for ($i = 0; $i < 10; $i++) { $randstring = $characters[rand(0, strlen($characters))]; } return $randstring; } RandomString(); echo $randstring; ?> - function generateRandomString($length = 10) {
$characters = ‘0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ’;
$randomString = »;
for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) — 1)]; } return $randomString; } - function generateRandomString($length = 15)
{
return substr(sha1(rand()), 0, 0);
} - function RandomString($length) {
$keys = array_merge(range(0,9), range(‘a’, ‘z’));
for($i=0; $i < $length; $i++) { $key = $keys[array_rand($keys)]; } return $key; }
Answers:
- 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.
Answers:
- empty() checks if a variable is empty.
- empty() can check expressions.
- empty() can only check variables.
- empty() returns false if a variable exists and has a non-empty value.
Answers:
- CGI is a standard method for web server software to delegate the generation of web content to executable files.
- CGI is the part of the Web server that can communicate with other programs running on the server.
- A CGI program is any program designed to accept and return data that conforms to the CGI specification. The program can only be written in PHP.
- A CGI program is any program designed to accept and return data that conforms to the CGI specification. The program could be written in any programming language C, Perl, Java etc.
<?php
$x = 10;
if ($x == 10):
?>
<p>Hi!</p>
<?php else:?>
<p>Bye!</p>
<?php endif; ?>
Answers:
- Hi!
- Bye!
- The code will throw an error, as there is no curly brace after the if statement, and it has a misplaced colon(:).
- The code will throw an error, as there is no curly brace after the else statement, and it has a misplaced colon(:).
<?php
echo «<pre>»;
$array1 = array(
«1»=>»a»,
«2»=>»b»,
«3»=>»c»
);
$array = array_flip($array1);
print_r($array);
echo «</pre>»;
?>
Answers:
- Array
(
[1] => a
[2] => b
[3] => c
) - Array
(
[a] => 1
[b] => 2
[c] => 3
) - Array
(
[0] => c
[1] => b
[2] => a
) - Array
(
[0] => 1
[1] => 2
[2] => 3
)
«While sending a long string in PHP mail() a special character (!) is automatically inserted»
Which one of the following is true with respect to above statement?
Answers:
- There is a limit to the number of characters in a line of an email.
- The statement given is false and this never happens.
- This in a well known problem of PHP’s mail() function and can not be solved.
- None of the above.
<?php
$numbers=array();
$numbers[1] = 1;
$numbers[2] = 2;
$numbers[3] = 3;
$numbers[4] = 4;
$key= array_search(3,$numbers);
unset($numbers[$key]);
print_r($numbers);
?>
Answers:
- Array ( [1] => 1 [2] => 2 [3] => 4 )
- Array ( [1] => 1 [2] => 2 [4] => 4 )
- Array ( [0] => 1 [1] => 2 [2] => 4 )
- Array ( [0] => 1 [2] => 2 [3] => 4 )
Answers:
- cURL is not enabled.
- curl_init() is not a valid API.
- cURL only works on Linux.
- All of these.
Answers:
- Returns the available memory on RAM.
- Returns the peak of memory allocated by PHP.
- Returns the peak of memory allocated by OS.
- No such function exist.
Answers:
- The script will have no memory limit.
- The script will have 1 MB memory
- The script will have 1 KB memory
- parse error.
Answers:
- $string = explode($variable);
- $string = print_r($variable);
- $string = serialize($variable);
- $string = var_dump($variable);
Answers:
- Use enough random input for generating the session ID
- Use HTTPS to protect the session ID during transmission
- Set the cookie with the HttpOnly and Secure attributes to forbid access via JavaScript
- Regenerating the session ID after successful login
Answers:
- CDATA is used to store the content of an XML node.
- CDATA is used to skip invalid characters.
- XML does not have any CDATA section.
- CDATA is used when PHP is used to update the content of an XML file.
Answers:
- PHPTracer
- Zend Debugger
- APD
- Xdebug
Answers:
- There is a limit to number of mails can be send using mail() function.
- mail() function can not be used in a loop.
- mail() function opens and closes an SMTP socket for each email, which is not very efficient.
- There is no problem in using mail() function to send bulk mails.
Class Registry {
private $vars = array();
public function __set($key, $val) {
$this->vars($key) = $val;
}
public function __get($key) {
return $this->vars($key);
}
}
$registry = new Registry;
$registry->foo = “foo”;
echo $registry->foo;
What will be the output of the following code?
Answers:
- fatal error : undefined property foo
- foo
- nothing
- can not access the property foo outside the class Registry
Answers:
- krsort
- rsort
- array_multisort
- usort
session_start();
$_SESSION[‘logged’] = 1;
$_SESSION[‘id’] = $id;
$_SESSION[‘name’] = $contact_name;
$_SESSION[’email’] = $email;
Now how will you remove the email value from the session?
Answers:
- unset($_SESSION)
- unset($_SESSION[’email’])
- session_destory($_SESSION)
- All of the above.
Answers:
- Only certain rows are deleted in DELETE queries.
- Only a defined subset of rows are read in SELECT queries.
- Only certain users can access the database.
Answers:
- Bridge is designed up-front to let the abstraction and the implementation vary independently
- Decouple an abstraction from its implementation so that the two can vary independently.
- Publish interface in an inheritance hierarchy, and bury implementation in its own inheritance hierarchy.
- Use bridge when you do not want to share an implementation among multiple objects.
Answers:
- protected
- final
- Pstatic.
- private
Answers:
- E_STRICT
- E_ALL
- E_STRICT
- E_PARSE_ERROR
Answers:
- var_dump(isset($var))
- var_dump(is_null($var))
- var_dump(empty($var))
- var_dump(defined($var))
<?php
class FormBuilder
{
private $elements = array();
public function label($text) {
$this->elements[] = «<label>$text</label>»;
return $this;
}
public function input($type, $name, $value = ») {
$this->elements[] = «<input type=\»$type\» name=\»$name\» value=\»$value\» />»;
return $this;
}
public function textarea($name, $value = ») {
$this->elements[] = «<textarea name=\»$name\»>$value</textarea>»;
return $this;
}
public function __toString() {
return join(«\n», $this->elements);
}
}
$b = new FormBuilder();
echo $b->label(‘Name’)->input(‘text’, ‘name’)->textarea(‘message’, ‘My message’);
Answers:
- <label>Name</label>
- <label>Name</label>
<input type=»text» name=»name»/>
<textarea name=»message»>My message</textarea> - <label>Name/label>
<input type=»text» name=»name» value=»» />
<textarea name=»message»>My message</textarea> - Fatar error on the last line since calling of class methods can not be nested.
Answers:
- Request.Form;
- $_GET()
- Request.Get;
- $_GET[];
Answers:
- $animals = array (Cat, Dog, Horse);
- $animals = array (“Cat”, “Dog”, “Horse”);
- $animals = array [Cat, Dog, Horse];
- $animals = “Cat”, “Dog”, “Horse”;
Answers:
- __LINE__
- __FILE__
- __FUNCTION__
- __CLASS__
Answers:
- <script…/script>
- <?php>…</?>
- <?php…?>
- <&>…</&>
Answers:
- __construct(), __destruct(), __put(), __post()
- __construct(), __destruct(), __get(), __set()
- __init(), __final(), __get(), __set()
- __init(), __final(), __put(), __post()
Answers:
- mysqliconnect()
- mysqli-connect()
- mysqli_connect()
- sql_connect()
Answers:
- mysqli_stmt_execute()
- mysqli_execute_stmt()
- mysqli_query()
- mysqli_stmt_bind_param()
$a = “b”;
$b = 22;
echo $$a + 40
Answers:
- 22
- 40
- 62
- 0
Answers:
- $_DOMAIN[‘REMOTE_ADDR’]
- $_SERVER[‘REMOTE_ADDR’]
- $_SERVER[‘REMOTE_IP_ADRESS’]
- $_ENV
try {
$a = 10/0;
echo $a;
} catch (Exception $e) {
echo ‘You cannot divide by ZERO!!’ ;
}
Answers:
- You cannot divide by ZERO!!
- 10
- Warning: Division by zero
- 0
const ONE = 1;
class foo {
const TWO = ONE * 2;
const THREE = ONE + self::TWO;
const SENTENCE = ‘The value of THREE is ’.self::THREE;
}
echo foo::SENTENCE . “\n”;
Answers:
- The value of THREE is 1
- The value of THREE is 12
- The value of THREE is 3
- The value of THREE is 13
Answers:
- String
- Bool
- Char
- Integer
- UInt
Answers:
- last()
- before()
- prev()
- Integer
- previous()
Answers:
- SELECT
- Select
- select
- SeLeCt
- All of the above
Answers:
- fgetss()
- fgets()
- fopen()
- file_strip_tags()
Answers:
- open(«sample.txt»);
- open(«sample.txt», «read»);
- fopen(«sample.txt», «r+»);
- fopen(«sample.txt», «r»);
function validateDate($date, $format = ‘Y-m-d H:i:s’)
{
$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
}
Answers:
- validateDate(‘2012-02-30 12:12:12’)
- validateDate(’30/02/2012′, ‘d/m/Y’)
- validateDate(’14:77′, ‘H:i’)
- validateDate(‘2012-02-28 12:12:12’)
Note: There may be more than one right answer.
Answers:
- is_readable()
- file_exists()
- feof()
- is_file_exists()
class foo {
public $bar = <<<‘EOT’ bar line1 line2 EOT; public function printbar(){ echo $this->bar;
}
}
$myobj = new foo;
$myobj->printbar();
Answers:
- bar
- bar
line1
line2 - bar line1 line2
- Error
Answers:
- unlink()
- unset()
- delete()
- remove_file()
session_start();
$_SESSION[‘logged_in’] = true;
$_SESSION[‘name’] = ‘Jane’;
$_SESSION[‘level’] = 4;
echo session_encode();
Answers:
- logged_in|b:1;name|s:4:»Jane»;level|i:4;
- Array ( [logged_in] => 1 [name] => Jane [level] => 4
- {«logged_in»:true,»name»:»Jane»,»level»:4}
- You cannot encode session variables.
Answers:
- E_PARSE
- E_CORE_ERROR
- E_ERROR
- E_RECOVERABLE_ERROR
Answers:
- to determine how many instances a PHP variable has
- to determine whether a PHP variable is an instantiated object of a certain class
- to make a copy of a PHP variable
- none of all listed above
Answers:
- InnoDB
- BDB
- NDB Cluster
- MyISAM
Answers:
- throw new Exception(message);
- throw Exception(message);
- throws new Exception(message);
- None of these
Note: There may be more than one right answer.
Answers:
- $a=+1
- $a++
- ++$a
- a++
$sentence = «ThiS iS a SenTEnCe»;
echo ucwords($sentence);
Answers:
- This Is A Sentence
- THIS IS A SENTENCE
- this is a sentence
- ThiS IS A SenTEnCe
Answers:
- The email is reached to the client’s mail server.
- The local mail server (or the SMTP configured in php.ini) accepted the outgoing email for delivery.
- The local mail server (or the SMTP configured in php.ini) has sent the email.
- None of the above.
Answers:
- unserialize()
- __wakeup
- __sleep
<?php
$size =$_POST[‘size’];
$query = «SELECT id, name, inserted, size FROM products WHERE size = ‘$size’»;
$result = pg_query($conn, $query);
?>
Answers:
- SQL query syntax is not correct as a result database error will be thrown
- Variable $size is not validated and escaped therefore SQL Injection can be executed
- «pg_query» is not a PHP operator
- $_POST is not correct a Superglobal variable
Answers:
- throws new Exception();
- throw new Exception();
- new Exception();
- new throws Exception();
Answers:
- save_data
- session_save
- session.save_data
- session.save_handler
Answers:
- ‘Content-type: html; charset=iso-8859-1’ . «\r\n»;
- ‘MIME-Version: 1.0’ . «\r\n» — пока это
- ‘Content-type: text/html; charset=iso-8859-1’ . «\r\n»
- ‘Content-type: application/html; charset=iso-8859-1’ . «\r\n»
error_reporting(E_ALL & ~E_NOTICE);
Answers:
- Report all errors
- Report only NOTICE messages
- Report all errors other than NOTICE messages
<?php
class Foo {
private function printName($name) {
print_r($name);
}
}
$a = new Foo();
$a->printName(‘James’);
?>
Answers:
- James
- Fatal error: Call to private method Foo::printName() from context …
- Notice: Undefined variable: a
- Fatal error: Call to undefined method Foo::printName()
Answers:
- PDO
- MYSQLi
- MYSQL
Answers:
- array_random()
- array_rand()
- shuffle()
- rand()
Answers:
- fopen()
- fread()
- filesize()
- file_exists()
Answers:
- func_num_args()
- $_GET
- func_get_args_num()
- func_get_arg()
Answers:
- try
- catch
- throw
- throws
$foo = 10;
$bar = ’10’;
if ($foo === $bar){
echo ‘I ran’;
}
Answers:
- I ran
- Nothing is output
- TRUE
- Error
Answers:
- get_headers($url);
- get_header($url);
- get_headers($url,1);
Answers:
- get_headers($url);
- get_header($url);
- get_headers($url,1);
Answers:
- All the methods of the class should be private.
- This pattern is used when you need only a small number of instances of same type.
- Using this pattern consumes a lot of memory.
- Instances of a class which are identical are shared in an implementation instead of creating a new instance of that class for every instance.
Answers:
- It returns the array of all the defined variables.
- It returns the array of all the defined variables of a function.
- It returns all the $_POST variables only.
- It returns all the $_GET variables only
$array = array (true => ‘5’, 1 => ‘6’);
Answers:
- 1
- 2
- 3
- 4
Answers:
- strtoarray
- explode
- extract
- substr
Answers:
- $start = microtime();
functionToProfile();
$end = microtime();
$duration = $end — start; - $start = time();
functionToProfile();
$end = time();
$duration = $end — start; - $start = microtime(true);
functionToProfile();
$end = microtime(true);
$duration = $end — start; - $start = date(‘U’);
functionToProfile();
$end = date(‘U’);
$duration = $end — start;
Note: There may be more than one right answer.
Answers:
- $_23
- ${«foobar»}
- &$foo
- $23_foobar
- $foobar
$time = strtotime (‘2016-01-01’);
echo date (‘d-m-y H:i:s:u’, $time);
Answers:
- 16-01-01 00:00:00:00
- 01-01-16 00:00:00:000000
- 01-01-2016 00:00:00:000000
- 01-01-16 00:00:00:00
- filesize()
- cURL
- file_exists()
- stat()
SELECT * from students
Note: There may be more than one right answer.Answers:
- mysqli_affected_rows()
- mysqli_num_rows()
- mysqli_use_result()
- mysqli_fetch_lengths()
Answers:
- CURL can be used to authenticate a user.
- CURL can be used to send form data using both GET and POST methods.
- CURL can not be used to authenticate a user as it can only be used to access and read webpage data.
- CURL can be used for HTTP Basic Authentication.
Answers:
- getMessage()
- getCode()
- getFile()
- getLine()
Answers:
- 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.
Answers:
- Use mysql_query() and variables: for example: $input = $_POST[‘user_input’]; mysql_query(«INSERT INTO table (column) VALUES (‘» . $input . «‘)»);
- Use PDO prepared statements and parameterized queries: for example: $input= $_POST[«user-input»] $stmt = $pdo->prepare(‘INSERT INTO table (column) VALUES («:input»); $stmt->execute(array(‘:input’ => $input));
- Use mysql_query() and string escaped variables: for example: $input= $_POST[«user-input»] $input_safe = mysql_real_escape_string($input); mysql_query(«INSERT INTO table (column) VALUES (‘» . $input. «‘)»);
- Use mysql_query() and variables with a blacklisting check: for example: $blacklist = array(«DROP»,»INSERT»,»DELETE»); $input= $_POST[«user-input»] if (!$array_search($blacklist))) mysql_query(«INSERT INTO table (column) VALUES (‘» . $input. «‘)»);
Answers:
- mail($to,$subject,$body)
- sendmail($to,$subject,$body)
- mail(to,subject,body)
- sendmail(to,subject,body)
Answers:
- $e = new Exception; var_dump($e->debug());
- $e = new Exception; var_dump($e->getTraceAsString());
- $e = new Exception; var_dump($e->backtrace());
- $e = new Exception; var_dump($e->getString());
<?php
var_dump (3*4);
?>
Answers:
- int(3*4)
- int(12)
- 3*4
- 12
- None of the above
Answers:
- session(start);
- session();
- session_start();
- login_sesion();
Answers:
- Use an MVC design pattern.
- As PHP is a scripting language, HTML and PHP cannot be separated.
- Use any PHP template engine e.g: smarty to keep the presentation separate from business logic.
- Create one script containing your (PHP) logic outputting XML and one script produce the XSL to translate the XML to views.
Answers:
- $array_variable = get_object_vars($object);
- $array_variable = (array)$object;
- $array_variable = array $object;
- $array_variable = get_object_vars $object;
Answers:
- Mysqli provides the procedural way to access the database while PDO provides the object oriented way.
- Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS.
- MySQLi prevents SQL Injection whereas PDO does not.
- MySQLi is used to create prepared statements whereas PDO is not.
Answers:
- <
- >
- single quote
- double quote
- &
- All of these
Answers:
- delete()
- delete_file()
- unlink()
- unlink()
- fdelete()
- file_unlink()
Answers:
- 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.
- 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.
$size=X(filename);
Answers:
- filesize
- size
- sizeofFile
- getSize
Answers:
- is_numeric («200»)
- is_numeric («20,0»)
- is_numeric («$200»)
- is_numeric («.25e4»)
- None
<?php
$xmlFile = «<root><css><element><csstag><title>background-color</title><value>#FFF</value></csstag><csstag><title>color</title><value>#333</value></csstag><csstag><title>font-family</title><value>Verdana, Geneva, sans-serif</value></csstag></element></css></root>»;
$xml = simplexml_load_string($xmlFile);
foreach($xml->css as $css) {
echo (string) $css->element[‘id’].»{«;
foreach($xml->css->element->csstag as $tag) {
$temp = $tag->title.»: «.$tag->value.»;»;
echo $temp;
}
echo «}»;
}
?>
Answers:
- syntax error
- background-color: #FFF;color: #333;font-family: Verdana, Geneva, sans-serif;
- parse error;
- {background-color: #FFF;color: #333;font-family: Verdana, Geneva, sans-serif;}
<?php
echo «<pre>»;
$array1 = array(
«1»=>»a»,
«2»=>»b»,
«3»=>»c»
);
$array = array_flip($array1);
print_r($array);
echo «</pre>»;
?>
Answers:
- Array
(
[1] => a
[2] => b
[3] => c
) - Array
(
[a] => 1
[b] => 2
[c] => 3 - Array
(
[0] => c
[1] => b
[2] => a
) - Array
(
[0] => 1
[1] => 2
[2] => 3
)
Which of the following will produce a Boolean value of true?
?
Answers:
- var_dump(isset($var))
- var_dump(is_null($var))
- var_dump(empty($var))
- var_dump(defined($var))
No comments:
Post a Comment