Given a PHP value, which sample shows how to convert the value to JSON?
A. $string = json_encode($value);
B. $string = Json::encode($value);
C. $json = new Json($value); $string = $json->__toString();
D. $value = (object) $value; $string = $value->__toJson();
Which MIME type is always sent by a client if a JPEG file is uploaded via HTTP?
A. image/jpeg
B. image/jpg
C. image/pjpeg
D. Depends on the client system
How can the id attribute of the 2nd baz element from the XML string below be retrieved from the SimpleXML object
found inside $xml?
A. $xml->getElementById('2');
B. $xml->foo->bar->baz[2]['id']
C. $xml->foo->baz[2]['id']
D. $xml->foo->bar->baz[1]['id']
E. $xml->bar->baz[1]['id']
What is the output of the following code?
$text = 'This is text';
$text1 = <<<'TEXT'
$text
TEXT;
$text2 = << $text1 TEXT; echo "$text2"; A. This is text B. $text C. $text1 D. $text2
Consider the following two files. When you run test.php, what would the output look like?
test.php:
include "MyString.php";
print ",";
print strlen("Hello world!");
MyString.php:
namespace MyFramework\String;
function strlen($str)
{
return \strlen($str)*2; // return double the string length
}
print strlen("Hello world!")
A. 12,12
B. 12,24
C. 24,12
D. 24,24
E. PHP Fatal error: Cannot redeclare strlen()
What is the output of the following code?
$a = 3; switch ($a) {
case 1: echo 'one'; break;
case 2: echo 'two'; break;
default: echo 'four'; break;
case 3: echo 'three'; break;
}
A. one
B. two
C. three
D. four
When uploading a file to a PHP script using the HTTP PUT method, where would the file data be found?
A. the $_FILES super-global
B. the input stream php://input
C. the $_POST super-global
D. the global variable scope
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);
A. 5
B. 10
C. 50
D. Fatal error
What is the output of the following code?
class test {
public $value = 0;
function test() {
$this->value = 1;
}
function __construct() {
$this->value = 2;
}
}
$object = new test();
echo $object->value;
A. 2
B. 1
C. 0
D. 3
E. No Output, PHP will generate an error message.
What is the output of the following code?
function append($str)
{
$str = $str.'append';
}
function prepend(and$str)
{
$str = 'prepend'.$str;
}
$string = 'zce';
append(prepend($string));
echo $string;
A. zceappend
B. prependzceappend
C. prependzce
D. zce