Question:* What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection.
Answer: • 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));
Question:* Which of the following methods should be used for sending an email using the variables $to, $subject, and $body?
Answer: • mail($to,$subject,$body)
Question:* Which of the following is used to maintain the value of a variable over different pages?
Answer: • session_register()
Question:* Which of the following will check if a function exists?
Answer: • function_exists()
Question:* Which of the following is not a file-related function in PHP?
Answer: • fappend
Question:* Which of the following is true about the singleton design pattern?
Answer: • A singleton pattern means that a class can have only one instance object.
Question:* Which of the following characters are taken care of by htmlspecialchars?
Answer: • All of these
Question:* Which of the following will read an object into an array variable?
Answer: • $array_variable = get_object_vars($object);
Question:* Which of the following variable declarations within a class is invalid in PHP?
Answer: • internal $term = 3;
Question:* Which of the following is not a PHP magic constant?
Answer: • __TIME__
Question:* Which of the following will print out the PHP call stack?
Answer: • $e = new Exception;
var_dump($e->getTraceAsString());
Question:* What will be the output of the following code?
<?php
var_dump (3*4);
?>
Answer: • int(12)
Question:* Which of the following is correct about Mysqli and PDO?
Answer: • Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS.
Question:* What is the correct way to send a SMTP (Simple Mail Transfer Protocol) email using PHP?
Answer: • mail($EmailAddress, "Subject", $MessageBody);
Question:* Which of the following will start a session?
Answer: • session_start();
Question:* For the following code:
<?php
function Expenses()
{
function Salary()
{
}
function Loan()
{
function Balance()
{
}
}
}
?>
Which of the following sequence will run successfully?
Answer: • Expenses();Salary();Loan();Balance();
Question:* What enctype is required for file uploads to work?
Answer: • multipart/form-data
Question:* Which of the following is incorrect with respect to separating PHP code and HTML?
Answer: • As PHP is a scripting language, HTML and PHP cannot be separated.
Question:* Which one of the following is not an encryption method in PHP?
Answer: • bcrypt()
Question:* What function should you use to join array elements with a glue string?
Answer: • implode
Question:* Which function can be used to delete a file?
Answer: • unlink()
Question:* What is the string concatenation operator in PHP?
Answer: • .
Question:* Which of the following is useful for method overloading?
Answer: • __call,__get,__set
Question:* Which of the following will store order number (34) in an 'OrderCookie'?
Answer: • setcookie("OrderCookie",34);
Question:* What would occur if a fatal error was thrown in your PHP program?
Answer: • The PHP program will stop executing at the point where the error occurred.
Question:* What is the correct line to use within the php.ini file, to specify that 128MB would be the maximum amount of memory that a script may use?
Answer: • memory_limit = 128M
Question:* What is the best way to change the key without changing the value of a PHP array element?
Answer: • $arr[$newkey] = $arr[$oldkey];
unset($arr[$oldkey]);
Question:* What will be the output of the following code?
<?
echo 5 * 6 / 2 + 2 * 3;
?>
Answer: • 21
Question:* Does PHP 5 support exceptions?
Answer: • Yes
Question:* Which PHP function opens a file for reading only?
Answer: • fopen("c:\\test\\time.txt" , "r");
Question:* The logical operator OR is similar to:
Answer: • ||
Question:* How do you add a multi-line comment in PHP?
Answer: • /* This is a comment */
Question:* If a string is enclosed in double-quotes, PHP will interpret more escape sequences for special characters such as
Answer: • All of these
Question:* How do you write "Hello World" in PHP
Answer: • echo "Hello World";
Question:* What is the correct way to create a function in PHP?
Answer: • function myFunction(){ echo "Example function.\n";};
Question:* Which of the following variables is not a predefined variable?
Answer: • $ask
Question:* What does the acronym LAMP stand for?
Answer: • Linux Apache MySQL PHP (or Perl/Python)
Question:* What is the output from this example? $str = "My name is O\'Connor."; echo stripslashes($str);
Answer: • My name is O'Connor.
Question:* Which datatypes are treaded as arrays?
Answer: • strings
Question:* In PHP the error control operator is _______
Answer: • @
Question:* <?php $array1= array(“fast”, "faster”); $array1[0] = “faster”; if ($array1[1] == “faster”) { $array1[1]= “fastest”; } foreach($array1 as $output) { echo $output . " "; } ?>
Answer: • faster fastest
Question:* What is the result of the following code: $array[]="value";
Answer: • adds new element at the end of the array
Question:* In PHP, the die() and exit() language constructs perform the same function.
Answer: • True
Question:* Which character is used to separate namespaces in PHP?
Answer: • Backslash (\)
Question:* What is the correct way to assign a class constant?
Answer: • const MY_CONSTANT = 'value';
Question:* Which function can be used to simplify searches in databases where you know the pronunciation but not the spelling
Answer: • soundex
Question:* What is the default timeout of a PHP session cookie ?
Answer: • Until the browser is closed
Question:* What is the result of the following code ? <?php $a = 1; echo $a++; $a *= 2; echo ++$a; ?>
Answer: • 15
Question:* What is the result of the following code : <?php echo (strpos('abcdef', 'a')) ? : -1; ?>
Answer: • -1
Question:* Which function is used to read an entire file into an array ?
Answer: • file
Question:* What does this code do? namespace Hello\World;
Answer: • It creates two namespaces : "Hello" and "Hello\World"
Question:* In PHP, variables always start with which symbol?
Answer: • $
Question:* Which of the following is not a valid PHP variable declaration?
Answer: • $10_var
Question:* The PHP function which capitalizes the first letter of each word in a string
Answer: • ucwords()
Question:* PHP's echo and print functions are not exactly alike. Which will accept multiple parameters and concatenate them in its "without parentheses" form?
Answer: • echo
Question:* What does the use of the final keyword in a method declaration prevent?
Answer: • Child classes from overriding the method.
Question:* Which of the following statements is NOT true for PHP constants?
Answer: • The scope of a constant is local.
Question:* Which PHP function will return a file's last access time?
Answer: • fileatime()
Question:* What is default session time in PHP?
Answer: • 1440 seconds or 24 minutes.
Question:* Which of those is not magic method?
Answer: • __toInt
Question:* What is the recommendation regarding PHP closing tags in a document?
Answer: • Omit the closing tag when the file contains only PHP code.
Question:* What is PHAR?
Answer: • The PHP way to distribute entire applications within a single file ("PHP Archive")
Question:* Which of the following will return TRUE?
Answer: • is_numeric(M_PI)
Question:* What is the primary difference between interfaces and abstract classes in PHP?
Answer: • Interfaces cannot have function implementations.
Question:* Which character is used to separate namespaces in PHP?
Answer: • Backslash (\)
Question:* What does this output? $pos = strpos('Atlanta', 'a'); echo $pos;
Answer: • 3
Question:* If one wants to convert all double quotes (") to a backslash followed by a double quote (\") which of the following can be used?
Answer: • addslashes()
Question:* What function creates a cookie?
Answer: • setcookie()
Question:* Which PHP functions generate random numbers following algorithms known as Mersenne Twister?
Answer: • mt_rand() and mt_srand()
Question:* Which statement will NOT combine strings $s1 and $s2 into a single string?
Answer: • $s1 + $s2
Question:* The following code does what? <?php $textfile = "my_file.txt"; $file = fopen("$textfile", 'r+'); ?>
Answer: • opens the file, “my_file.txt” for reading and writing
Question:* How to capture exception message of a try / catch? Note: consider Exception $e
Answer: • $e->getMessage();
Question:* What is the way to use the magic method '__toString()' of this Class ? class exampleClass { protected $a= 1; protected $b= 2; function __toString() { return 'a= '. $this->a . ',b= '. $this->b; } }
Answer: • All of the these.
Question:* What is the result of casting the integer 1 to an array: (array) 1
Answer: • A numerically indexed array with one element who's value is 1
Question:* What do anonymous functions do in PHP?
Answer: • allow the creation of functions with no name
Question:* What function sets the default timezone used by all date and time functions in a script?
Answer: • date_default_timezone_set('Region');
Question:* What is one of the difference between the use of single quotes and double quotes in PHP syntax?
Answer: • variable names will be expanded in double quotes
Question:* Which of the following string delimiting methods is known as the heredoc syntax?
Answer: • delimited by <<< identifier
Question:* $table = array("old_value"); foreach($table as $row) { $row="new_value"; } echo $table[0]; will produce:
Answer: • "old_value"
Question:* Which PHP function closes an open SQLite database?
Answer: • sqlite_close($dbhandle);
Question:* Which function sorts an array in descending order?
Answer: • rsort()
Question:* What does the following code: $array[]="value";
Answer: • adds new element at the end of the array
Question:* Choose the string for which the POSIX regular expression ^[A-Za-z]$ matches.
Answer: • P
Question:* Which of the following functions allows you to split a string by a regular expression and put the results into an array?
Answer: • preg_split()
Question:* Given the following code, the Atom class can access which variables? class Flash { public $fast; private $superSpeed; private $ultraSonic; protected $warp; } class Atom extends Flash { }
Answer: • $fast, $warp
Question:* Given the statement, mysqli_connect(“happy.com”, “hot24”, “015A#”, “ABC”); “happy.com” and “hot24” respectively refer to ?
Answer: • Host, username
Question:* What's the MIME type for images with correct extension "jpg"?
Answer: • image/jpeg
Question:* What is default session time in PHP ?
Answer: • 1440 Seconds
Question:* The PHP instruction header("Content-Type: text/plain") should be sent:
Answer: • before any output is sent
Question:* Which of the following will this function output: <? $father="mother"; $mother="son"; echo $$father; ?>
Answer: • son
Question:* The only code construct allowed before a namespace declaration is the declare statement, for defining encoding of a source file
Answer: • true
Question:* What is the default execution time for a PHP script?
Answer: • 30 secs
Question:* What will be the result of the following: echo ucwords(strtoupper('aAaA bBbB'));
Answer: • AAAA BBBB
Question:* Which compound type is supported by PHP?
Answer: • array
Question:* Which of the following functions would allow you to convert a string to an array?
Answer: • explode()
Question:* How do you create a non-public method, which can be used in a child-class?
Answer: • protected function Something() {
Question:* How would you delete a cookie?
Answer: • set the expiration date in the past
Question:* What will range('a', 'z') return?
Answer: • An alphabetically ordered array of letters from 'a' to 'z'
Question:* Which one removes a cookie from client's browser?
Answer: • setcookie('mycookie', '', time()-3600);
Question:* Which one removes a cookie from client's browser?
Answer: • setcookie('mycookie', '', time()-3600);
Question:* What variable scope would you use if you wanted a function variable which does not discard it's value when the function has completed execution?
Answer: • static
Question:* Error reporting constants are used to adjust error reporting settings. Which of the following is NOT a valid error reporting constant?
Answer: • E_CONSTANT
Question:* function foo($bar) { if($bar['soap'] != 'Zest') { return $bar['soap']; } } Which best describes the function foo()?
Answer: • The parameter(s) passed to it is/are an associative array
Question:* What is the value of $res in the following script? <?php $str = "1"; $int = 1; $res = ($str === $int); ?>
Answer: • False, because the variables $str and $int are not of the same type.
Question:* The following would return? extract( array( 'sexy' => 'a', 'and' => 'b', 'i' => 'c', 'know' => 'd', 'it' => 'e' ) ); return $sexy.$and.$i.$know.$it;
Answer: • abcde
Question:* $val = ""; What will isset($val) return?
Answer: • true
Question:* What will be displayed? <?php $var = "6"; var_dump($var); $var++; var_dump($var); ?>
Answer: • string(1) "6" int(7)
Question:* Which function returns the contents of the output buffer and empties the buffer?
Answer: • ob_get_clean();
Question:* echo substr("Hello world",-4); the right output is?
Answer: • orld
Question:* In this example code, $result = print_r ($a); $result is the
Answer: • variable.
Question:* Which type of array allows you to use textual keys so that array indices can be more descriptive?
Answer: • Associative
Question:* Self-contained collections of functions AND properties are referred to as
Answer: • objects.
Question:* The interpreter executes one PHP command which ends in a semi-colon. This is referred to as a
Answer: • PHP statement.
Question:* natsort( array( "i10", "i1", "i20" ) ) = ?
Answer: • array( "i1", "i10", "i20" )
Question:* Which of the following is the scope resolution operator in PHP?
Answer: • ::
Question:* The break statement ends execution of which of the following structures?
Answer: • All of these
Question:* What is meaning of PEAR?
Answer: • PHP Extension and Application Repository
Question:* What is the value of $start after exiting the for loop? <?php $start=5; for ($i=0; $i !=1; $i++) { $start= $start - 2; } ?>
Answer: • 3
Question:* The following code will produce: var_dump(5 === "5");
Answer: • bool(false)
Question:* <?php $array1= array(“fast”, "faster”); $array1[0] = “faster”; if ($array1[1] == “faster”) { $array1[1]= “fastest”; } foreach($array1 as $output) { echo $output; } ?>
Answer: • faster fastest
Question:* Choose the variable assignment which is performed 'by value' in PHP.
Answer: • $value1= $value
Question:* Which of the following is not a valid key type for arrays in PHP?
Answer: • objects
Question:* The web server sets a cookie on the web client by sending the name/value pair as part of
Answer: • an HTTP header.
Question:* The case expression is used as part of a PHP ____.
Answer: • switch statement.
Question:* What separates a sequence of one or more characters used to specify the boundary between separate text regions?
Answer: • delimiter
Question:* Which PHP function sends a raw HTTP header to a client?
Answer: • header()
Question:* You can call a parent class' implementation of a method which is overridden by a child class using:
Answer: • parent::
Question:* Which variable assignment is 'by reference' in PHP?
Answer: • $value1= &$value;
Question:* To suppress error messages to the user, preface the PHP statement with
Answer: • @
Question:* Which PHP function returns "true" if a value already exists in an array?
Answer: • in_array()
Question:* True or False: There is no difference in using the following 2 examples: echo('string'); echo 'string';
Answer: • True
Question:* What does the following output? echo (5 % 3);
Answer: • 2
Question:* How do I typecast a variable to boolean?
Answer: • $var = (bool)$var;
Question:* Which rule determines which sections of script are able to access which variables?
Answer: • Variable Scope
Question:* What is the scope of a PHP constant?
Answer: • global
Question:* Which variable name is incorrect?
Answer: • $1first
Question:* How would you create a numeric array from the following string that did not include "-test" and where each digit had its own array key? $str = '6.1.4.2.6-test';
Answer: • $arr = explode('-', $str); $arr = explode('.', $arr[0]);
Question:* The comparison $a <> $b means
Answer: • $a is not equal to $b
Question:* Choose the output of the following script. <?php $rest = substr("abcdef", -1); echo $rest; ?>
Answer: • f
Question:* Which PHP function checks to see if a file exists and is writable?
Answer: • is_writable()
Question:* What is the difference between the include() and require() language constructs?
Answer: • They handle failure differently.
Question:* Choose the correct output. <?php $data = "98.8degrees"; $data = (double)$data; echo $data; ?>
Answer: • 98.8
Question:* Which of the following is the correct way to add comments to PHP?
Answer: • All listed methods are valid
Question:* Which PHP function sorts an array and maintains index association?
Answer: • asort()
Question:* In this example code, $result = print_r($a); $a is the
Answer: • argument
Question:* Is $_SERVER['PHP_SELF'] subject to injection vulnerabilities?
Answer: • Yes, it's vulnerable. On most servers PATH_INFO is supported, which is part of PHP_SELF
Question:* What is a collection of characters that is treated as one entity called?
Answer: • String
Question:* The PHP mail() function allows you to...
Answer: • send mail messages directly from a script.
Question:* Which PHP function or variable will return the value of current session id?
Answer: • session_id()
Question:* Variables in PHP are represented by a dollar sign followed by the name of the variable. A valid name must NEVER start with a...
Answer: • number.
Question:* Which function advances the internal array pointer of an array?
Answer: • next()
Question:* Which of the following is valid PHP syntax?
Answer: • if($a == 5) echo "a = 5";
Question:* What is the GD Library?
Answer: • It is a library that gives the PHP the capability to create and manipulate image files. - (Gif Draw)
Question:* Which of the following is false?
Answer: • PHP applications must be compiled.
Question:* Which of the following outputs a formatted string?
Answer: • printf("Hello %s", $name);
Question:* OCI8, PostgreSQL, and SQLSRV are all examples of
Answer: • database extensions available in PHP.
Question:* Which statement is true regarding the XML support in PHP?
Answer: • All of these
Question:* Which function sets the internal pointer of an array back to its first element?
Answer: • reset()
Question:* Which of the following language constructs is used to terminate a running script?
Answer: • exit()
Question:* What is output by the following: $c = 1; ++$c; echo $c++;
Answer: • 2
Question:* Which statement would produce the output, "I love summer"?
Answer: • All of these
Question:* What does this function do: function my_func($variable) { return (is_numeric($variable) && $variable % 2 == 0); }
Answer: • Tests whether $variable is an even number
Question:* Which PHP function will combine two arrays?
Answer: • array_merge()
Question:* What function can be used to help prevent MySQL injection?
Answer: • mysql_real_escape_string()
Question:* Which function allows you to delete a file?
Answer: • unlink
Question:* Which of the following functions changes directory on ftp-connection?
Answer: • ftp_chdir()
Question:* What is a large binary data object called in PHP?
Answer: • blob
Question:* In PHP, you can use both single quotes ( ' ' ) and double quotes ( " " ) for strings.
Answer: • True, but double quotes will expand PHP variables and escape sequences inside it.
Question:* Which PHP function creates an array by using one array for keys and another for its values?
Answer: • array_combine()
Question:* Choose the word(s) that describe the fundamental style of programming for PHP.
Answer: • All of these
Question:* What type of statements tell your PHP script to execute a section of code only if certain criteria are met?
Answer: • Conditional
Question:* What does the acronym LAMP stand for?
Answer: • Linux Apache MySQL PHP/Perl/Python
Question:* Which keyword causes a conditional loop to skip to the start of the next iteration?
Answer: • continue
Question:* Which function removes all HTML and PHP tags?
Answer: • strip_tags()
Question:* Which of the following is the recommended standard (short_opentag=Off) for opening and closing a PHP code block?
Answer: • '<?php' to open and '?>' to close
Question:* What type of operator is && in PHP?
Answer: • logical operator
Question:* What does the following PHP statement create? define("FIRST-NAME","John");
Answer: • a constant
Question:* How can we increase the execution time of a PHP script from setting php.ini?
Answer: • By setting max_execution_time
Question:* What will it output? <?php $var = "pontus, patrik, felix"; $var = explode(", ", $var); echo count($var); ?>
Answer: • 3
Question:* Which function converts a string to all uppercase characters?
Answer: • strtoupper()
Question:* Which PHP extension provides an abstract method for database retrieval?
Answer: • PDO
Question:* True or False? Arrays in PHP can only hold the same data type.
Answer: • False
Question:* What is output to the screen when executing code: $> php -r 'echo echo "a";'
Answer: • PHP Parse error
Question:* What is the output? <?php $boolean= true; while ($boolean) { $boolean =false; echo "false"; }
Answer: • false
Question:* What are the default header request protocols defined in PHP?
Answer: • All of these
Question:* Which following function is used to count total number of characters in a string?
Answer: • strlen();
Question:* Which PHP function returns an array with elements in reverse order?
Answer: • array_reverse()
Question:* HTTP cookies can be used to:
Answer: • identify a user.
Question:* A fatal run-time error would be caught by
Answer: • E_ERROR
Question:* What PHP function counts elements in an array, or properties in an object?
Answer: • count()
Question:* Which of the following displays the browser properties using PHP?
Answer: • $_SERVER['HTTP_USER_AGENT']
Question:* Which function checks for the existence of a particular key?
Answer: • array_key_exists()
Question:* Which is an example of a statement using a combined operator?
Answer: • $a += $b
Question:* The setcookie() function must appear _____ the <html> tag.
Answer: • before
Question:* If you would like to check to see if a PHP variable has data, which of the following language constructs would you use?
Answer: • empty().
Question:* What is the output from this example? $str = "My name is O\'Connor."; echo stripslashes($str);
Answer: • My name is O'Connor.
Question:* An array in PHP is an ordered map which associates
Answer: • keys to values.
Question:* What function converts 'Hatfields & McCoys' into 'Hatfields & McCoys'?
Answer: • htmlentities()
Question:* Which of the following is NOT a function of PHP session support?
Answer: • session_pw
Question:* Which type is not supported by PHP?
Answer: • time
Question:* The PHP operator, %, which returns the remainder of an equation is called the:
Answer: • modulus
Question:* Include files can have which file extensions?
Answer: • Any of these
Question:* PHP requires instructions to be terminated at the end of each statement with a
Answer: • ;
Question:* Which of the following statement best describes: $panther = new Animal();
Answer: • Instantiation of an object
Question:* Which PHP math function would you use to round a number upwards to the nearest integer?
Answer: • ceil()
Question:* What function is used to check if a variable is an array?
Answer: • is_array()
Question:* What will be the result of this code: <?php $text1 = "Test"; $text2 = "Test"; if($text1 == md5($text2)) { echo "Yes"; } else { echo "No"; }
Answer: • No
Question:* What is the output of flowing code? <?php $cars=array("Volvo","BMW","Toyota"); sort($cars); $clength=count($cars); for($x=0;$x<$clength;$x++) { echo $cars[$x]; echo " "; } ?>
Answer: • BMW Toyota Volvo
Question:* What will this return: $value="Hello_World"; $rt=explode("_",$value); echo $rt[0];
Answer: • Hello
Question:* How do you perform a strict comparison of variables for type and value?
Answer: • $a === $b
Question:* Which statement is true about PHP constants?
Answer: • All of these.
Question:* Which statement correctly declares a float variable in PHP?
Answer: • All of these
Question:* Which function allows you to split a string into an array of substrings by a string delimiter?
Answer: • explode(" ", $str)
Question:* When using the POST method, variables are displayed in the URL:
Answer: • False
Question:* What is the result of the following code? <?php $hello ="HELLO"; $hello=lcfirst($hello); echo $hello; ?>
Answer: • hELLO
Question:* True or false? We can include ("sandy.php") two times in one PHP page "my.php".
Answer: • True
Question:* mysqli_num_rows() function is used to:
Answer: • Count number of rows in result of MySql Query.
Question:* What is the value of $var when the following line is executed in a PHP function? unset($var);
Answer: • NULL
Question:* What is the right way to set a value on an object stdClass?
Answer: • $variable->value = 'value';
Question:* How do you specify a string literal in PHP?
Answer: • All of these
Question:* To output information about a variable use the function
Answer: • var_dump()
Question:* An array in PHP is:
Answer: • a collection of key value pairs.
Question:* Which function returns one or more randomly selected keys from an array?
Answer: • array_rand()
Question:* What does this statement do? <?php echo b"testing string"; ?>
Answer: • It will throw an error
Question:* Which function tests a string for an exact match of the argument?
Answer: • preg_match()
Question:* Which variable contains values of $_GET, $_POST, and $_COOKIE?
Answer: • $_REQUEST
Question:* Which PHP function would you use to display information about variables in a simple, readable format?
Answer: • var_dump()
Question:* Which PHP function creates a directory on an FTP server?
Answer: • ftp_mkdir()
Question:* Can PHP be run on a Windows IIS server?
Answer: • true
Question:* __construct is a
Answer: • constructor for an object.
Question:* Which function allows you to specify a start position of a string and length arguments to retrieve part of a string?
Answer: • substr()
Question:* Which PHP function randomizes the order of the elements in an array?
Answer: • shuffle()
Question:* In PHP, which statement is used to retrieve browser properties?
Answer: • $_SERVER['HTTP_USER_AGENT'];
Question:* Which control statement indicates a block of code to be repeated a number of times?
Answer: • for
Question:* Which of the following variables does PHP make automatically available to you?
Answer: • $_SERVER
Question:* Which of the following stores PHP values, such as strings, numbers or arrays?
Answer: • variables
Question:* Which of the following is NOT used to specify PHP comments?
Answer: • <!-- -->
Question:* Given, the following: <?php $business = array("retail", "advertising", "computer"); echo current($business)."\n"; echo next($business)."\n"; echo $business[2]."\n"; ?> What is the output?
Answer: • retail advertising computer
Question:* Which of the following returns information passed via HTTP forms?
Answer: • All of these
Question:* Select the type of variable scope which is not supported by PHP:
Answer: • Hidden variables
Question:* Choose the correct value for $i. $i = 2; $i++;
Answer: • 3
Question:* Which function returns information on the PHP configuration you are using?
Answer: • phpinfo();
Question:* Which PHP math function would you use to return the number with the lowest value of two specified numbers?
Answer: • min()
Question:* What is the correct way to require the file "time.inc" in a manner which will halt the script upon failure?
Answer: • <?php require('time.inc'); ?>
Question:* Which of these does not represent a single, valid PHP variable
Answer: • $my-Var
Question:* PHP requires that instruction statements be terminated with a:
Answer: • semicolon
Question:* The practice of combining strings and variables into one string is called:
Answer: • concatenation
Question:* How to call a method from within a class?
Answer: • $this->my_function();
Question:* Which of the following checks if a value exists in an array?
Answer: • in_array
Question:* To modify the default PHP settings such as whether to accept the short form open tag (<?), you need to change the
Answer: • php.ini file.
Question:* $var = (10 % 2 == 0) ? true:false; What is the output of $var?
Answer: • true
Question:* How do you inherit the methods from BaseClass in MyClass?
Answer: • class MyClass extends BaseClass {
Question:* How do you define a constant in PHP?
Answer: • define("CONSTANT", "Hello world.");
Question:* Which PHP function returns part of a string?
Answer: • substr()
Question:* Which of these assigns a value of type string to variable $x?
Answer: • $x = "true";
Question:* Which statement returns the number of characters in the string variable $a?
Answer: • strlen($a)
Question:* What is meant by nl2br()?
Answer: • Inserts HTML line breaks (<BR />) before all newlines in a string.
Question:* Which PHP math function would you use to generate a random integer?
Answer: • rand()
Question:* Which PHP function would you use to display the value of an array in a readable format?
Answer: • print_r()
Question:* Include files must have the file extension ".inc"
Answer: • False
Question:* The FTP functions can be used to perform the following actions on file servers:
Answer: • All of these
Question:* Which of the following are examples of PHP comments?
Answer: • All of these
Question:* Which function gives you the current PHP version information?
Answer: • phpversion()
Question:* Which statements start a session and end a session?
Answer: • session_start(); session_destroy();
Question:* The concatenation operator in PHP is
Answer: • .
Question:* Which of the following is NOT a command for sending output to the standard output?
Answer: • send
Question:* Which construct is typically used for exception handling in PHP?
Answer: • try / catch
Question:* Which PHP function finds the position of the last occurrence of a substring within a string?
Answer: • strrpos()
Question:* What do you need to call in order for your session variables to work?
Answer: • session_start()
Question:* Which function can be used to convert 'ff' to 255?
Answer: • hexdec()
Question:* Which PHP function opens a file for reading only?
Answer: • fopen("c:\\test\\time.txt" , "r");
Question:* In the following PHP script, $arr = array(1,2,3);, 1, 2, and 3 are the array
Answer: • values
Question:* Which function is used to perform a regular expression match in PHP?
Answer: • preg_match()
Question:* An example of a float in PHP is:
Answer: • All of these
Question:* What kind of error causes the termination of the script?
Answer: • Fatal Errors
Question:* Which of the following PHP language constructs allows you to combine code from one file into another?
Answer: • All of the these
Question:* Which of the following are PHP comparison operators?
Answer: • All of these
Question:* What is the correct way to create a function in PHP?
Answer: • function myFunction(){ echo "Example function.\n";};
Question:* In PHP in order to access MySQL database, use the:
Answer: • mysqli_connect() function
Question:* Which PHP function do you call to begin a PHP session?
Answer: • session_start();
Question:* Which PHP language construct sends output to a browser window?
Answer: • echo
Question:* Which of the following HTML form submission methods is suitable when you need to send large amounts of form data?
Answer: • Post
Question:* How do you add a multi-line comment in PHP?
Answer: • /* This is a comment */
Question:* Which of the following variables is expected to contain information about the user's browser?
Answer: • $_SERVER['HTTP_USER_AGENT'];
Question:* Which of the following is a string operator?
Answer: • dot(.)
Question:* How is the following statement interpreted in PHP? $i = 1;
Answer: • $i is assigned a value of 1
Question:* The PHP syntax is most similar to:
Answer: • Perl and C
Question:* HTML form input needs to be validated in order to avoid:
Answer: • All of these
Question:* The statement header('Location: http://www.somesite.com'); will
Answer: • redirects the browser to www.somesite.com.
Question:* Which statement allows you to add new records to a MySQL database table?
Answer: • INSERT INTO
Question:* Which is a characteristic of the PHP language?
Answer: • All of these
Question:* Which operator is used to concatenate strings in PHP?
Answer: • dot (.)
Question:* Which PHP function completely destroys all data relevant to the session?
Answer: • session_destroy();
Question:* Placing ++ in front of variable:
Answer: • preincrements the variable by one
Question:* A string literal in PHP can be specified in the following way(s):
Answer: • All of these
Question:* Which of the following function libraries are supported in PHP?
Answer: • All of these
Question:* Which function creates a directory on the FTP server?
Answer: • ftp_mkdir()
Question:* The logical operator OR is equivalent to:
Answer: • ||
Question:* Which variable is not predefined by PHP?
Answer: • $_ASK
Question:* What PHP function calculates the sum of the values in an array?
Answer: • array_sum()
Question:* Can PHP scripts be embedded directly into XHTML documents?
Answer: • Yes
Question:* An example of a PHP string is:
Answer: • "test"
Question:* What should you do in advance, to get and set session variable
Answer: • session_start()
Question:* strpos() stands for
Answer: • string position.
Question:* If a string is enclosed in double-quotes, PHP will interpret more escape sequences for special characters such as
Answer: • All of these
Question:* How do you combine multiple arrays into one single PHP array?
Answer: • array_merge()
Question:* What does MVC stand for?
Answer: • Model View Controller
Question:* What are int, float, string and boolean examples of in PHP?
Answer: • data types
Question:* Choose the statement which produces this output: This is an example.
Answer: • <?php echo "This is an example."; ?>
Question:* How do you retrieve the value of a variable called "name" which has been passed from a submitted form?
Answer: • $_GET["name"];
Question:* CakePHP, Zend, and CodeIgniter are popular _________ used on many PHP servers.
Answer: • development frameworks
Question:* If the allow_url_fopen configuration setting is enabled, which of the following functions will be able to open remote urls?
Answer: • All of these
Question:* In PHP, functions using global variables must declare the variables by using
Answer: • the GLOBAL keyword.
Question:* One way to output a string in PHP is:
Answer: • echo()
Question:* What's the output? $name = 'John'; echo 'Hi there '.$name;
Answer: • Hi there John
Question:* Which function will generate random integers?
Answer: • rand()
Question:* Which of the following is a valid PHP function modifier?
Answer: • All of these
Question:* Which PHP function sorts an array?
Answer: • sort()
Question:* Variables in PHP start with a
Answer: • dollar sign($)
Question:* What types of arrays are supported in PHP?
Answer: • All of these
Question:* In PHP, how would you determine if a variable is set?
Answer: • isset()
Question:* Which variable is used to collect values of a form sent via the HTTP POST method?
Answer: • $_POST
Question:* Which is a valid loop method in PHP?
Answer: • All of these
Question:* Which construct includes an external PHP file?
Answer: • All of these
Question:* How do you write "Hello World" in PHP
Answer: • echo "Hello World";
Question:* Which function checks for a specific PHP data type?
Answer: • All of these
Question:* PHP variables always begin with
Answer: • a dollar sign($).
Question:* Which function would you use to check for data type?
Answer: • All of these
Question:* The function mysql_connect( ) takes following parameter(s):
Answer: • All of these
Question:* All variables in PHP start with which symbol?
Answer: • $
Question:* PHP supports which of the following features?
Answer: • All of these
Question:* The PHP language can be used on the following operating systems:
Answer: • All of these
Question:* Choose the output of the following code. Assume that today is 2009-3-19:2:45:32 pm <?php $today = date("F j, Y"); ?>
Answer: • March 19, 2009
Question:* What function converts newlines to HTML line breaks in a string?
Answer: • nl2br()
Question:* Which PHP function can be used to generate a unique ID for members of your site?
Answer: • uniqid()
Question:* Which PHP string function is used to convert the first letter of a string to uppercase?
Answer: • ucfirst()
Question:* Which function displays a formatted string?
Answer: • printf()
Question:* After a file is successfully opened in PHP, how do you retrieve a line from the file?
Answer: • fgets
Question:* What is the result of the following code? <?php $test =array("five", "six", 3, 4); $hold= count($test); echo $test; ?>
Answer: • Array
Question:* Which PHP function tells whether a file exists and is readable?
Answer: • is_readable()
Question:* In the date() function what does the 'm' format character do?
Answer: • Insert month as 01 through 12
Question:* What is returned by array_product( array( 2, 3) )?
Answer: • 6
Question:* dirname(__FILE__) will return what?
Answer: • The directory in which the currently invoked file is located
Question:* Which is a valid character for starting a PHP function name?
Answer: • underscore(_)
Question:* Which PHP function removes the last value of an array and returns it?
Answer: • array_pop()
Question:* The PHP statement: $i[2] = "orange"; is an example of
Answer: • a numeric array.
Question:* What does the return code E_ERROR indicate?
Answer: • Fatal run-time error
Question:* Which function exchanges all keys with their associated values in an array?
Answer: • array_flip(array)
Question:* Which type of control structure should NOT be used to check for a condition being met?
Answer: • try / catch
Question:* To access functions of an instantiated class, you use the following:
Answer: • $class->function()
Question:* In PHP, the die() and exit() language constructs perform the same function.
Answer: • True
Question:* What will be the value of $result? <?php $myArr = array( 'val1' => 1, 'val2' => array('val21' => 21, 'val22' => 22), 'val3' => 3 ); $result = array_key_exists('val22', $myArr); ?>
Answer: • false
Question:* What function can you use to create your own streams using the PHP stream wrappers and register them within PHP?
Answer: • stream_wrapper_register
Question:* How can you call this function? $greet = function($name) { printf("Hello %s\r\n", $name); };
Answer: • $greet('World');
Question:* How can we set the default time zone using PHP?
Answer: • date_default_timezone_set(timezone_identifier);
Question:* Which methods are available in PHP to read a remote file?
Answer: • All of these
Question:* Which PHP function checks to see if HTTP headers have been sent?
Answer: • headers_sent()
Question:* Which of the following would be accepted as an argument parameter in the following function: function getEmotion(Emotion $emotion) { ... }
Answer: • All of these
Question:* Choose the correct output for: $x=array(2=>"mouse",7=>"keyboard"); $y=array_keys($x); echo $y[1];
Answer: • 7
Question:* Upon completion of a file upload in PHP, the UPLOAD_ERR_OK error code is returned. What does this indicate?
Answer: • The file uploaded with success.
Question:* Which function opens an SQLite database and creates the database if it does not exist?
Answer: • sqlite_open()
Question:* Which PHP function checks a month, day, and year number to determine if they form a valid Gregorian date?
Answer: • checkdate()
Question:* print_r( 2 ) outputs:
Answer: • 2
Question:* $a='1'; extract( array( 'a' => '2' ) ); echo $a; outputs ...
Answer: • 2
Question:* The function setcookie( ) is used to
Answer: • create, update, or delete a cookie header in the HTTP response
Question:* Which of the following functions can be used to execute a shell command?
Answer: • All of these
Question:* What is input sanitization?
Answer: • Removing or cleaning potentially malicious user input.
Question:* The function checkdate() returns what data type?
Answer: • Boolean
Question:* Which libraries are available for using regular expressions in PHP?
Answer: • Both of these.
Question:* To determine if the file pointer is at the end of a successfully opened file, use the...
Answer: • feof() function.
Question:* PHP scripts can be saved, and included later, under which allowed file extensions?
Answer: • Any File Extension
Question:* Variable $a has not been declared. With error reporting turned off, what is the result of: $a[1][2]=3;?
Answer: • A multi-level array structure is created with 3 as a value.
Question:* What is the correct way to assign a class constant?
Answer: • const MY_CONSTANT = 'value';
Question:* $_SERVER, $_COOKIE, $_FILES, $_ENV are examples of PHP built-in variables called:
Answer: • superglobals
Question:* The comparison $a xor $b evaluates to...
Answer: • TRUE if either $a or $b is TRUE, but not both.
Question:* PHP variable $hello is set to “HELLO WORLD". Which statement would return "Hello World" instead?
Answer: • echo ucwords(strtolower($hello));
Question:* Which of the following functions is used to format a number ?
Answer: • number_format();
Question:* Which of these is correct usage of the chmod() function?
Answer: • chmod('/path/to/file', 0755);
Question:* Which PHP function will return an array of values from $start to $end.
Answer: • range( $start, $end);
Question:* Which statement opens a file for writing, to append data at the end of its content ?
Answer: • fopen("myFile", "a")
Question:* Which function removes the first element from an array, and returns the value of the removed element?
Answer: • array_shift()
Question:* Which of the following is true about the "touch" function in PHP? Signature: touch($filename, $time) : boolean
Answer: • If the file does not exist, it will be created.
Question:* In PHP5, your "construct" method must be named the exact same thing as your "class".
Answer: • False
Question:* When using php cli how can you return the same info as phpinfo()
Answer: • php -i
Question:* How do single quotes interpret strings in PHP?
Answer: • literally
Question:* class A{} class_alias( 'A', 'B' ); var_dump(new B); outputs ...
Answer: • object(A)#1 (0) { }
Question:* Which PHP function is used to replace a string?
Answer: • All of these
Question:* What is the output of the following code? $one='two'; $two='one'; echo $$$one;
Answer: • two
Question:* Which of the following functions does not have a resource for a return type?
Answer: • strrpos()
Question:* What will the following code output: array_map("print_r", array( 'a', 'b' ) );
Answer: • ab
Question:* What will be the output for the following code? $values = array(0, NULL, FALSE); foreach($values as $key => $value) { echo isset($values[$key]) ? "TRUE " : "FALSE "; }
Answer: • TRUE FALSE TRUE
Question:* When passing an object to json_encode(), the default behavior can be modified by:
Answer: • Implementing the JsonSerializable interface.
Question:* What is the correct way to call an anonymous function?
Answer: • $func($var);
Question:* Given an array of images, $images = array("img12.png", "img10.png", "img2.png", "img1.png"), which function will sort $images into ("img1.png", "img2.png", "img10.png", "img12.png")?
Answer: • natsort($images);
Question:* Which PHP function would you use to get information about the current session cookie?
Answer: • session_get_cookie_params()
Question:* is_a( $a, $b ) will:
Answer: • check if $a is of class "$b" or has this class as one of its parents
Question:* How do you get the number of arguments passed to a PHP function?
Answer: • None of these
Question:* "virtual()" in PHP
Answer: • is an Apache-specific function
Question:* Which of the following code snippets will split a string into an array with 3 elements?
Answer: • All of them
Question:* An object can be counted with count() and sizeof() if it:
Answer: • None of the above
Question:* Which type of error can NOT be caught with a custom error handler?
Answer: • E_ERROR
Question:* What is the output of the following code? <?php echo str_pad("abc", 6, "7"); ?>
Answer: • abc777
Question:* What will be the final structure of the following array? $animals = array( 'dog', 'cat', true => 'lion' );
Answer: • array( 0 => 'dog', 1 => 'lion' ) - boolean true will be changed to integer 1
Question:* What is the value of $a in the following: <?php $a = array_pad( array( 0 ), 2, 1 ); ?>
Answer: • array( 0, 1 )
Question:* use keyword is used only for namespace
Answer: • false
Question:* Which mode parameter should be used with the fopen() function to open a file and point to the end for writing only?
Answer: • a
Question:* $a = array('a' => 0, 'b' => 0, 'c' => 1, 'd' => 2); $b = array_flip($a); var_dump($b); What does the 'var_dump' function show ?
Answer: • array(3) { [0]=> string(1) "b" [1]=> string(1) "c" [2]=> string(1) "d" }
Question:* Which function would you use to obtain the ASCII value of a character?
Answer: • ord( );
Question:* What does the following PHP code do? preg_filter($pattern, $replace, $subject)
Answer: • Performs a regular expression search and replace
Question:* What does the glob() function return?
Answer: • An array of filenames / directories matching a specified pattern
Question:* True or False? Within the eval() function, code must be opened and closed with PHP tags, i.e. <?php echo 'hi'; ?>
Answer: • False, but you can still exit and enter PHP mode using tags
Question:* Sleep(3000); will sleep the page for?
Answer: • 3000 seconds
Question:* Choose the correct output of: <?php $email = 'admin@domain.tld'; echo strstr($email, '@'); ?>
Answer: • @domain.tld
Question:* Which of the following superglobals doesn't contain data from the client?
Answer: • $_SESSION
Question:* What are Traits in PHP?
Answer: • Traits allow code reuse without direct inheritance.
Question:* What is the time complexity of a call to array_search()?
Answer: • O(N)
Question:* <?php $x = false or true; $y = false || true; var_dump($x); var_dump($y);
Answer: • bool(false) bool(true)
Question:* Which of the following functions inserts one or more elements to the beginning of an array?
Answer: • array_unshift()
Question:* Which elements can be encapsulated by namespaces?
Answer: • Classes, functions and constants
Question:* Which function can be used to convert data into a binary string according to a specified format?
Answer: • pack()
Question:* What is the result of calling json_encode() on an empty array?
Answer: • [] - An empty JavaScript array
Question:* Which function returns an item from the argument list?
Answer: • func_get_arg()
Question:* What is the time complexity of a call to array_key_exists()?
Answer: • O(1)
Question:* How do you call a static method defined by the called class from a parent class?
Answer: • static::someFunc();
Question:* What does mt_srand( [int $a] ); do?
Answer: • Initializes a random number generator
Question:* Which of the following is the predefined class in PHP?
Answer: • __PHP_Incomplete_Class
Question:* Which of the following network transports doesn’t PHP support?
Answer: • pdc
Question:* What is the output for the following code? <?php $value1=5; $value2= $value1--; $value2= $value1++; echo $value2; ?>
Answer: • 4
Question:* What does this code do? namespace Hello\World;
Answer: • It creates two namespaces : "Hello" and "Hello\World"
Question:* What function allows you to print a backtrace?
Answer: • debug_print_backtrace
Question:* What data types cannot be used with PHP5 Type Hinting?
Answer: • Integer, Strings
Question:* Which of the following protocols is not supported by PHP streams?
Answer: • imap
Question:* What does this display? <?php $x = array('a'=>1, 'b'=>2, 'c'=>3); echo key($x);
Answer: • "a"
Question:* Which function returns the size of a specified file on the FTP server?
Answer: • ftp_size()
Question:* $a = array('z','x','y'); $b = sort($a); The value of $b is?
Answer: • True
Question:* Which of the following is not a valid PHP variable type conversion?
Answer: • object to reference
Question:* When adding ('+' function) two variables of type integer and type string, what type is the resulting value?
Answer: • Integer
Question:* Is there a function to listen on E_ERROR (fatal) errors?
Answer: • register_shutdown_function()
Question:* Is it possible to typehint function arguments using native types (String, Bool, Array, Int, Float, Binary...)?
Answer: • Only Array is supported
Question:* Which PHP extension allows you to simplify converting between different calendar formats?
Answer: • calendar
Question:* What is the output of the following code: <?php $x = 0x22; echo <<<'END' $x END; ?>
Answer: • $x
Question:* What is the result of : $a = "abcd"; if(strpos('a', $a)) { return true; } else { return false; }
Answer: • false
Question:* Which PHP function reads entire file into an array?
Answer: • file
Question:* Which subversion of PHP5 adds short array syntax?
Answer: • 4
Question:* In mail($param1, $param2, $param3, $param4), the $param2 contains:
Answer: • The subject
Question:* Name of the function to check the variable type is object
Answer: • is_object
Question:* What is the correct way to open the file "time.txt" as readable?
Answer: • fopen("time.txt","r");
Question:* Does PHP5 support Exceptions?
Answer: • Yes
Question:* How would you start a session
Answer: • session_start
Question:* ( (4 >= 4 && 8 < 1) || (44 == 33 || 5 > 3) ) will return
Answer: • TRUE
Question:* How can you enable the cURL extension?
Answer: • You should remove the semicolon in the front of "curl_extension" in php.ini.
Question:* $x = 10.88; echo (int) $x;
Answer: • 10
Question:* How can I identify the server IP address in PHP?
Answer: • $_SERVER['SERVER_ADDR'];
Question:* The function used to iterate over array and object.
Answer: • foreach
Question:* Which of the following function is used to check type of array
Answer: • is_array
Question:* (8 < 1 || 4 >= 4 ) will return
Answer: • True
Question:* $file = 'sample.txt'; $current = file_get_contents($file); $current .= "Additional Info"; file_put_contents($file, $current); What is the meaning of above code?
Answer: • It means that certain string of which value is 'Additional Info' is added to the end of the file named sample.txt.
Question:* True or false? One can include (âabc.PHPâ) two times in a PHP page âmakeit.PHPâ.
Answer: • True
Question:* What is the best way of writing an IF/ELSE statement on one line?
Answer: • echo ( $result ) ? "Win" : "Loss";
Question:* Which of the following is not a boolean false
Answer: • 1
Question:* Name of the function to check the variable type is object
Answer: • is_object
Question:* function foobar( ) { $a = func_get_args( ); return $a[2]; } print foobar('a',1,'b',2); What would the output be?
Answer: • b
Question:* True of false? PHP provides the goto in the latest version.
Answer: • True
Question:* What is the best way to URL encode a string?
Answer: • urlencode( $str )
Question:* Which of the following is not related to file
Answer: • fappend
Question:* $a = &$b; $b = 'Mary?'; print $a;
Answer: • Mary?
Question:* In mail($param1, $param2, $param3, $param4), the $param2 contains:
Answer: • The subject
Question:* A fatal error would be caught by
Answer: • E_ERROR
Question:* Which of these functions will not result in a runtime error if the file requested does not exist or can't be opened?
Answer: • include()
Question:* How can we delete a file using php function.
Answer: • unlink
Question:* Which of the following functions split the string and return the array?
Answer: • str_split()
Question:* Which array function checks if the specified key exists in the array?
Answer: • array_key_exists()
Question:* Which values should be assigned to the variables $a, $b and $c in order for the following script to display the string Hello, World! <?php $string= "Hello, World!"; $a =?; $b =?; $c =?; if($a) { if($b &&!$c){ echo "Goodbye Cruel World!"; } else if(!$b &&!$c) { echo "Nothing here"; } } else { if(!$b) { if(!$a && (!$b && $c)) { echo"Hello, World!"; } else { echo"GoodbyeWorld!"; } } else { echo "Not quite."; } } ?>
Answer: • False, False, True
Question:* How do you make PHP use a class file without having to require or include it manually?
Answer: • Define __autoload($class) magic function
Question:* What is the difference between $message and $$message?
Answer: • Classic example of PHP’s variable variables
Question:* What visibility level will this class property get in PHP5? var $cool = true;
Answer: • public
Question:* Which of the following is ternary operator
Answer: • ?:
Question:* How do you connect mysql with the use of PHP5 new functions?
Answer: • (both answers are correct)
Question:* Which of the following functions would one use to get the number of parameters passed?
Answer: • func_num_args
Question:* Which of the following is NOT supported in PHP5?
Answer: • Multiple Inheritance
Question:* The ____ operator is used to test if two values are identical in every way.
Answer: • ===
Question:* $text = 'He went to the school.'; echo strpbrk($text, 'w'); In the above code, what is the output?
Answer: • went to the school.
Question:* $a = array("pomme", "banane"); $b = array(1 => "banane", "0" => "pomme"); var_dump($a == $b); What does-it print ?
Answer: • TRUE
Question:* What is the primary difference between a method declared as static and a normal method?
Answer: • Static methods do not provide a reference to $this
Question:* Which of the lines below will output the following string: "PHP is "super easy" to use!"
Answer: • echo "PHP is \"super easy\" to use!";
Question:* Which function would you use to append one or more elements to the end of the array?
Answer: • array_push()
Question:* In PHP5 >= 5.3.0, which new operator was added?
Answer: • GOTO
Question:* What is PEAR in PHP?
Answer: • PHP Extension and Application Repository
Question:* Which of the following function is used to display the properties of variable?
Answer: • var_dump
Question:* How to open file in read/write mode?
Answer: • $handle = fopen("http://www.example.com/", "r+");
Question:* The PHP syntax is most similar to
Answer: • Perl and C
Question:* Given: $email = ‘bob@example.com’; which code block will output example.com?
Answer: • print substr($email, strpos($email, ‘@’) + 1);
Question:* Which of the following is a php resource?
Answer: • (all of these)
Question:* Which of the following crpto return longest hash value
Answer: • sha1()
Question:* Which of the following functions allows you to store session data in a database?
Answer: • session_set_save_handler();
Question:* Which function will list files and directories inside the specified path?
Answer: • scandir()
Question:* Which of the following variable is not related to file upload
Answer: • max_execution_size
Question:* What is the difference between idate and date function?
Answer: • idate function always returns an integer, but date function returns formatted date string or FALSE.
Question:* Which function can be used to rename files?
Answer: • rename()
Question:* $sweet = array('1' => 'apple', '2' => 'banana'); $fruits = array('delicious' => $sweet, 'sweet' => 'strawberry'); function myprint($item, $key) { echo "$key is $item\n"; } array_walk_recursive($fruits, 'myprint'); In above code, what is the output?
Answer: • [1 is apple] [2 is banana] [sweet is strawberry]
Question:* Include files must have the file extension ".inc"
Answer: • No
Question:* What is output of the following code. $arr = "a"; $arr[0]="b"; echo $arr; echo $arr[0];
Answer: • bb
Question:* What is the correct way to include the file "time.inc" ?
Answer: • <?php include "time.inc"; ?>
Question:* How do you kill or destroy a session?
Answer: • session_destroy();
Question:* To ensure that a given object has a particular set of methods, you must provide a method list in the form of an ________ and then attach it as part of your class using the ________ keyword.
Answer: • interface, implements
Question:* How to check if a directory exists?
Answer: • file_exists($name);
Question:* What is the best way to iterate and modify every element of an array using PHP 5?
Answer: • foreach($array as $key => &$val) { /* ... */ }
Question:* The contents of an image file are stored in memory as $imString, but the original file is not available. Of the following, which uses the least amount of code and is a valid method of retrieving the dimensions of $imString?
Answer: • return getimagesizefromstring($imString);
Question:* Which of the following functions set options in curl script?
Answer: • curl_setopt()
Question:* Which of the following functions compare the substrings of the parameters?
Answer: • substr_compare()
Question:* Which of the following is a correct declaration?
Answer: • Static $var = array(10,'str',3);
Question:* Which of following functions get a list of response headers sent (or ready to send)?
Answer: • headers_list()
Question:* How do you get header information from a URL?
Answer: • get_headers()
Question:* How should you filter variables before passing to header()?
Answer: • PHP's doing this itself nowadays
Question:* Which variable type can NOT be used as a type hint?
Answer: • resource
Question:* What is the output in following codes? <?php $array1 = array("a" => "green", "red", "blue"); $array2 = array("b" => "green", "yellow", "red"); $result = array_intersect($array1, $array2); print_r($result); ?>
Answer: • Array ( [a] => green [0] => red )
Question:* $a = array("pomme", "banane"); $b = array(1 => "banane", "0" => "pomme"); var_dump($a === $b); What does-it print ?
Answer: • FALSE
Question:* How do you instantiate a new object from class foo? class foo { function do_foo() { echo "Doing foo."; } }
Answer: • $bar = new foo;
Question:* <?php abstract class Animal { function greeting() { $sound = $this->sound(); return strtoupper($sound); } function sound(); } class Dog extends Animal { function sound() { return "Woof!"; } } $dog = new Dog(); echo $dog->greeting(); ?>
Answer: • Fatal error
Question:* What will the following script output? <?php $a = array (‘a’ => 20, 1 => 36, 40); array_rand ($a); echo $a[0]; ?>
Answer: • Nothing
Question:* echo new stdClass == new stdClass, '-', new stdClass !== new stdClass;
Answer: • 1-1
Question:* Which function would you use to prepend one or more elements to the beginning of an array?
Answer: • array_unshift()
Question:* What is the function to report errors from mysqli functions or queries?
Answer: • mysqli_report();
Question:* $i = 5; print $i++ + ++$i;
Answer: • 12
Question:* Which of the following functions is a relative ftp function new to PHP5?
Answer: • ftp_alloc()
Question:* What will be output of this code. function test(&$var) { $var=$var-1; return $var; } $returnVar = test(50); echo $returnVar. " is answer.";
Answer: • Error message
Question:* What will be the result of the following code ? $a = 0 or 1; $b = 0 || 1; echo "$a, $b";
Answer: • 0, 1
Question:* The number of parameters in setCookie function
Answer: • 7
Question:* What does php_strip_whitespace function return?
Answer: • Returns the PHP source code in filename with PHP comments and whitespace removed.
Question:* Which of following functions compute the intersection of arrays with additional index check and are defined newly in PHP5?
Answer: • array_uintersect_assoc(); array_uintersect_uassoc();
Question:* $file = 'sample.txt'; $current = file_get_contents($file); $current .= "Additional Info"; file_put_contents($file, $current); What is the meaning of above code?
Answer: • It means that certain string of which value is 'Additional Info' is added to the end of the file named sample.txt.
Question:* How to open file in read/write mode?
Answer: • $handle = fopen("http://www.example.com/", "r+");
Question:* What is the correct way to include the file "time.inc" ?
Answer: • <?php include "time.inc"; ?>
Question:* How can I identify the server IP address in PHP?
Answer: • $_SERVER['SERVER_ADDR'];
Question:* What Does OOM mean?
Answer: • Object Oriented Model
Question:* Which of the lines below will output the following string: "PHP is "super easy" to use!"
Answer: • echo "PHP is \"super easy\" to use!";
Question:* What function in PHP allows you to find the position of the first occurrence of a substring?
Answer: • strpos()
Question:* True or false? PHP provides the goto in the latest version.
Answer: • True
Question:* How do you make PHP use a class file without having to require or include it manually?
Answer: • Define __autoload($class) magic function
Question:* In mail($param1, $param2, $param3, $param4), the $param2 contains:
Answer: • The subject
Question:* What is the primary difference between a method declared as static and a normal method?
Answer: • Static methods do not provide a reference to $this
Question:* How do you connect mysql with the use of PHP5 new functions?
Answer: • (both answers are correct)
Question:* Which of the following variables is not related to file upload?
Answer: • max_execution_size
Question:* What will be the output of the following code: <?php class A {} class B {} class C extends B {} class D { function sayHello (A $argument) { echo '$argument is an instance of A'; } function sayHello (B $argument) { echo '$argument is an instance of B'; } } $d = new D(); $c = new C(); $d->sayHello($c);
Answer: • PHP Fatal error
Question:* The contents of an image file are stored in memory as $imString, but the original file is not available. Of the following, which uses the least amount of code and is a valid method of retrieving the dimensions of $imString?
Answer: • return getimagesizefromstring($imString);
Question:* How should you filter variables before passing to header()?
Answer: • PHP's doing this itself nowadays
Question:* Which of the following is a correct declaration?
Answer: • Static $var = array(10,'str',3);
Question:* What result? $a = "1"; $a[$a] = "2"; echo $a;
Answer: • 12
Question:* $i = 5; print $i++ + ++$i;
Answer: • 12
Question:* What will be the array $b after executing this code? $a = array(1, 3, 5); $b = array(2, 4, 6); $b += $a;
Answer: • $b = array(2, 4, 6)
Question:* For PHP version <= 5.3, how can we activate error reporting for all levels?
Answer: • error_reporting(-1);
No comments:
Post a Comment