PHP's array functions such as array_values() can be used on an object if the object...
An HTML form has two submit buttons. After submitting the form, how can you determine with PHP which button was clicked?
When retrieving data from URLs, what are valid ways to make sure all file_get_contents calls send a certain user agent string? (Choose 2)
What is the output of the following code?
$a = array('a', 'b'=>'c');
echo property_exists((object) $a, 'a')?'true':'false';
echo '-';
echo property_exists((object) $a, 'b')?'true':'false';
What content-type is required when sending an HTTP POST using JavaScript to ensure that PHP can access the data?
Consider the following table data and PHP code. What is the outcome?
Table data (table name "users" with primary key "id"):
id name email
------- ----------- -------------------
1 anna alpha@example.com
2 betty beta@example.org
3 clara gamma@example.net
5 sue sigma@example.info
PHP code (assume the PDO connection is correctly established):
$dsn = 'mysql:host=localhost;dbname=exam';
$user = 'username';
$pass = '********';
$pdo = new PDO($dsn, $user, $pass);
$cmd = "SELECT * FROM users WHERE id = :id";
$stmt = $pdo->prepare($cmd);
$id = 3;
$stmt->bindParam('id', $id);
$stmt->execute();
$stmt->bindColumn(3, $result);
$row = $stmt->fetch(PDO::FETCH_BOUND);
Given the following array:
$a = array(28, 15, 77, 43);
Which function will remove the value 28 from $a?
Consider the following table data and PHP code, and assume that the database supports transactions. What is the outcome?
Table data (table name "users" with primary key "id"):
id name email
------- ----------- -------------------
1 anna alpha@example.com
2 betty beta@example.org
3 clara gamma@example.net
5 sue sigma@example.info
PHP code (assume the PDO connection is correctly established):
$dsn = 'mysql:host=localhost;dbname=exam';
$user = 'username';
$pass = '********';
$pdo = new PDO($dsn, $user, $pass);
try {
$pdo->exec("INSERT INTO users (id, name, email) VALUES (6, 'bill', 'delta@example.com')");
$pdo->begin();
$pdo->exec("INSERT INTO users (id, name, email) VALUES (7, 'john', 'epsilon@example.com')");
throw new Exception();
} catch (Exception $e) {
$pdo->rollBack();
}
What is the output of the following code?
class Base {
protected static function whoami() {
echo "Base ";
}
public static function whoareyou() {
static::whoami();
}
}
class A extends Base {
public static function test() {
Base::whoareyou();
self::whoareyou();
parent::whoareyou();
Given the following code, what is correct?
function f(stdClass &$x = NULL) { $x = 42; }
$z = new stdClass;
f($z);
var_dump($z);
Your application uses PHP to accept and process file uploads. It fails to upload a file that is 5 MB in size, although upload_max_filesize is set to "10M". Which of the following configurations could be responsible for this outcome? (Choose 2)
What is the output of the following code?
class Test {
public function __call($name, $args)
{
call_user_func_array(array('static', "test$name"), $args);
}
public function testS($l) {
echo "$l,";
}
}
class Test2 extends Test {
public function testS($l) {
echo "$l,$l,";
}
}
$test = new Test2();
$test->S('A');
Which interfaces could class C implement in order to allow each statement in the following code to work? (Choose 2)
$obj = new C();
foreach ($obj as $x => $y) {
echo $x, $y;
}
Which of the following code snippets DO NOT write the exact content of the file "source.txt" to "target.txt"? (Choose 2)
Which PHP function is used to validate whether the contents of $_FILES['name']['tmp_name'] have really been uploaded via HTTP, and also save the contents into another folder?
You'd like to use the class MyDBConnection that's defined in the MyGreatFramework\MyGreatDatabaseAbstractionLayer namespace, but you want to minimize *as much as possible* the length of the class name you have to type. What would you do?
What is the output of the following code?
echo 0x33, ' monkeys sit on ', 011, ' trees.';
What is the output of the following code?
function fibonacci (&$x1 = 0, &$x2 = 1)
{
$result = $x1 + $x2;
$x1 = $x2;
$x2 = $result;
return $result;
}
for ($i = 0; $i < 10; $i++) {
echo fibonacci() . ',';
}
What is the name of the key for the element in $_FILES['name'] that contains the provisional name of the uploaded file?
What is the output of the following code?
class Foo Implements ArrayAccess {
function offsetExists($k) { return true;}
function offsetGet($k) {return 'a';}
function offsetSet($k, $v) {}
function offsetUnset($k) {}
}
$x = new Foo();
echo array_key_exists('foo', $x)?'true':'false';
Which string will be returned by the following function call?
$test = '/etc/conf.d/wireless';
substr($test, strrpos($test, '/')); // note that strrpos() is being called, and not strpos()
What is the output of the following code?
function increment ($val)
{
$_GET['m'] = (int) $_GET['m'] + 1;
}
$_GET['m'] = 1;
echo $_GET['m'];
What is the output of the following code?
function increment ($val)
{
$val = $val + 1;
}
$val = 1;
increment ($val);
echo $val;
What will be the output value of the following code?
$array = array(1,2,3);
while (list(,$v) = each($array));
var_dump(current($array));