Given the following code, what is correct?
function f(stdClass &$x = NULL) { $x = 42; }
$z = new stdClass;
f($z);
var_dump($z);
What can prevent PHP from being able to open a file on the hard drive (Choose 2)?
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()
Which of the following filtering techniques prevents all cross-site scripting (XSS) vulnerabilities?
Which of these elements can be encapsulated by namespaces and made accessible from the outside?
Which PHP function sets a cookie whose value does not get URL encoded when sending it to the browser?
When a query that is supposed to affect rows is executed as part of a transaction, and reports no affected rows, it could mean that: (Choose 2)
What is the return value of the following code?
strpos("me myself and I", "m", 2)
What is the name of the PHP function used to automatically load non-yet defined classes?
PHP's array functions such as array_values() can be used on an object if the object...
When uploading a file to a PHP script using the HTTP PUT method, where would the file data be found?
Given the following code, what will the output be:
trait MyTrait {
private $abc = 1;
public function increment() {
$this->abc++;
}
public function getValue() {
return $this->abc;
}
}
class MyClass {
use MyTrait;
public function incrementBy2() {
$this->increment();
$this->abc++;
}
}
$c = new MyClass;
$c->incrementBy2();
var_dump($c->getValue());
How many elements does the array $matches from the following code contain?
$str = "The cat sat on the roof of their house.";
$matches = preg_split("/(the)/i", $str, -1, PREG_SPLIT_DELIM_CAPTURE);
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');
How should class MyObject be defined for the following code to work properly? Assume $array is an array and MyObject is a user-defined class.
$obj = new MyObject();
array_walk($array, $obj);
What information can be used to reliably determine the type of an uploaded file?
What is the output of the following code?
class Number {
private $v;
private static $sv = 10;
public function __construct($v) { $this->v = $v; }
public function mul() {
return static function ($x) {
return isset($this) ? $this->v*$x : self::$sv*$x;
};
}
}
$one = new Number(1);
$two = new Number(2);
$double = $two->mul();
$x = Closure::bind($double, null, 'Number');
echo $x(5);
Please provide the name of the super-global variable where all the information about cookies is available.
Given the following code, how can we use both traits A and B in the same class? (select all that apply)
trait A {
public function hello() {
return "hello";
}
public function world() {
return "world";
}
}
trait B {
public function hello() {
return "Hello";
}
public function person($name) {
return ":$name";
}
}
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;
}
What is the output of the following code?
$first = "second";
$second = "first";
echo $$$first;
Consider the following code. Which keyword should be used in the line marked with "KEYWORD" instead of "self" to make this code work as intended?
abstract class Base {
protected function __construct() {
}
public static function create() {
return new self(); // KEYWORD
}
abstract function action();
}
class Item extends Base {
public function action() { echo __CLASS__; }
}
$item = Item::create();
$item->action(); // outputs "Item"