PHP 7.1 Fiverr Skills Test
Which of the given statements is correct about the following PHP 7.1 code snippet?
<?php
function example() {
foreach (range(5, 7) as $a){
yield;
}
}
var_dump(iterator_to_array(example()));
?>
The code will throw a compilation error.
The code will compile successfully but will not print anything.
The code will compile successfully and will print the following:
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
The code will compile successfully and will print the following:array(3) {
[0]=>
Five
[1]=>
Six
[2]=>
Seven
}
What is the correct output of the following PHP 7.1 code snippet?
<?php
interface exp1
{
const c = 'First Example';
}
echo exp1 ::c;
class exp2 implements exp1
{
const c = 'Second Example';
}
echo exp2::c;
?>
The code will throw a compilation error.
First Example
Fatal error
First Example
Second Example
First Example
First Example
Which of the given options is correct about the following PHP 7.1 code?
<?php
class example
{
function do_example()
{
echo "Testing example code.";
}
}
$b = new example;
$b->do_example();
?>
The code will throw a compilation error.
The code will throw a runtime error.
The code will compile successfully but will not print anything.
The code will compile successfully and will print: Testing example code.
Which of the following options is used for checking the installed version of PHP 7.1 ?
$ php -v
$ php -ver
$ php check version
$ php check --ver
Which of the given statements is correct about the following PHP 7.1 code snippet?
<?php
const C = 2;
class example {
const D = C * 2;
const E = C + self::D;
const F = 'The result is '.self::E;
}
echo example::D, PHP_EOL;
echo example::F;
?>
The code will throw a compilation error.
The code will compile successfully and will print the following output:
Four
The result is Six
The code will compile successfully and will print the following output:
4
The result is 6
The code will compile successfully and will print the following output:
C * 2
The result is
In relation to PHP 7.1 error handling, error reporting should be set to which of the following options in the development environment?
E.NOTICE
E_ALL
E.STRICT
E.DEPRECATED
Which of the given options is the correct output of the following code?
<?php
$result = 'Ip -sl';
echo "<pre>$result</pre>";
?>
<pre>Ip -sl</pre>
<pre>Failed to exec: 'Ip -si'
</pre>
'Ip-si’
Compilation error.
What will be the output of the following PHP 7.1 code?
v<?php
for ($a = 2, $b = 1; $a <= 6; $b += $a, print $a, $a++);
?>
123456
23456
66666
Compilation error.
Find the output of the following PHP 7.1 code.
<?php
$a = 'Lisa';
$b = &$a;
$b = "I met $b";
echo $b;
echo $a;
?>
I met Lisa
I met $bl met Lisa
I met Lisal met Lisa
I met Lisa I met Lisa.
I met $b
Find the output of the following PHP 7.1 code snippet.
<?php
namespace A\B\C;
const E_ERROR = 32;
function strlen($s)
{
return \strlen($s) - 5;
}
echo E_ERROR, "\n";
echo INI_ALL, "\n";
echo strlen('abc'), "\n";
if (is_array('abc')) {
echo "is an example.\n";
} else {
echo "is a test.\n";
}
?>
32 7
1
is a test, is an example
32 is a test.
7
-1
32
7
-2
is a test.
Compilation error.
In PHP 7.1, the string session_create_id ([ string $prefix ]) function is used for creating a new session id. Which of the following characters are allowed by the parameter prefix?
, (Comma)
+ (Plus)
- (Minus)
= (Equal)
In PHP 7.1, what will be the output of the following code?
<?php
$example = array(2, 4, 6, 8, 10);
foreach ($example as $x => $value){
unset($example[$x]);
}
print_r($example);
$example[] = 12;
print_r($example);
$example = array_values($example);
$example[] = 14;
print_r($example);
?>
Array (
)
Array
(
[0] =>12
)
Array
(
[1] => 14
)
Array
(
)
Array
(
[5] => 12
)
Array
(
[0] => 12
[1] => 14
)
Array (
[0] => 2
[1] => 4
[2] => 6
[3] => 8
[4] => 10
)
Array
[5] =>12
)
Array
[5] => 14
The code will throw a syntax error.
Which of the given statements is correct about the following PHP 7.1 code?
<?php
interface ExampleInterface
{
}
class ExampleClass implements Exampleinterface
{
}
$x = new ExampleClass;
$y = new ExampleClass;
$z = 'ExampleClass';
$p = 'NotExampleClass';
var_dump($x instanceof $y);
var_dump($x instanceof $z);
var_dump($x instanceof $p);
?>
The code will compile successfully and will print the following output:
bool(true)
bool(true)
bool(true)
The code will compile successfully and will print the following output:
bool(true)
bool(true)
bool(false)
The code will compile successfully and will print the following output:
bool(false)
bool(true)
bool(false)
The code will not compile and will throw an error.
What will be the output of the following PHP 7.1 code snippet?
<?php
class Bar
{
public function checking()
{
return function() {
var_dump($this);
};
}
}
$object = new Bar;
$function = $object->checking();
$function();
?>
object(exp) #1(1) {
)
Bar
object(Bar)#1 (0) {
)
Compilation error
Which of the following is an invalid constant in PHP 7.1?
exp1
1exp
_exp1
exp_2
Which of the given statements is correct about the following PHP 7.1 code?
<?php
$example = 25;
$b = &$example;
$b = &(12 * 9);
function t()
{
return 15;
}
$b = &t();
?>
The code will throw an error.
The code will compile successfully but will not print any output.
The code will print the output: 15.
The code will print the output: 108.
Which of the given options is the correct output of the following PHP 7.1 program?
<?php
function swap(&$x, &$y): void
{
if ($x === $y) {
return;
}
$exp = $x;
$x = $y;
$y = $exp;
}
$var1 = 12;
$var2 = 20;
var_dump(swap($var1, $var2), $var1, $var2);?>
NULL
int(20)
int(12)
12,20
NULL int(12) int(20)
The code will throw an error.
NULL
In PHP 7.1, which of the following cast options can be used for explicitly converting a value to integer?
int
integer
Either option a or b can be used.
Neither option a nor b can be used.
What will be the output of the following PHP 7.1 code?
<?php
class First
{
private $foo = 2;
protected $bar = 4;
protected function A_funct()
{
return 5;
}
public function B_funct()
{
return new class($this->foo) extends First {
private $test;
public function _construct($foo)
{
$this->test = $foo;
}
public function C_funct()
{
return $this->bar + $this->test + $this->A_funct();
}
};
}
}
echo (new First)->B_funct()->C_funct();?>
Compilation error.
9
6
11
What will be the output of the following PHP 7.1 code?
<?php
var_dump(0 == "x");
var_dump("2" == "02");
var_dump("20" == "2e2");
var_dump(200 == "2e4");
switch ("x") {
case 0:
echo "0";
break;
case "x":
echo "x";
break;
}
?>
bool(true)
bool(true)
bool(true)
bool(true)
x
bool(true)
bool(true)
bool(false)
bool(true)
0
bool(true)
bool(false)
bool(false)
bool(false)
x
bool(true)
bool(true)
bool(false)
bool(false)
0
What will be the output of the following PHP 7.1 code?
<?php
for($a=0,$b=20; $a<50; $a++) {
while($b--) {
if($b==8) goto end;
}
}
echo "a = $a";
end:
echo 'b and 8';
?>
b and 8
8
No output.
Compilation error.
In PHP 7.1, what will be the output of the following code?
<?php
$E_array = array(
"test" => "code",
64 =>46,
"multi" => array(
"dimensional" => array(
"array" => "test"
)
)
);
var_dump($E_array["test"]);
var_dump($E_array [64]);
var_dump($E_array["multi"]["dimensional"]["array"]);
?>
string(4) "code"
string(4) "test"
string(4) "code"
int(46)
string(4) "test"
string(4) "code"
int(46)
string(4) "Code"
The code will throw an error.
What will be the output of the following PHP 7.1 code?
<?php
class Example
{
public function abcFunction()
{
return Closure::fromCallable([$this, 'privateFunction']);
}
private function privateFunction($param)
{
var_dump($param);
}
}
$expFunc = (new Example)->abcFunction();
$expFunc('My New Example');?>
string(14) "My New Example"
string(2) "My"
string(1) ""
It will throw an error.
In PHP 7.1, which of the following options can be the key of an array?
Integer
Array
Object
String
What will be the output of the following PHP 7.1 code snippet?
<?php class f {
var $example = 'My name is example.';
var $array = array('My name is A.', 'My name is B.', 'My name is C.');
var $r = 'My name is r.';
}
$f = new f();
$example = 'example';
$b = array('f', 'example', 'b', 'c');
echo $f->$example. "\n";
echo $f->{$b[1]} . "\n";
$start = 'exa';
$end = 'mple';
echo $f->{$start. $end}. "\n";
$array = 'array';
echo $f->{$array[1]}. "\n";
?>
My name is A.
My name is B.
My name is C.
My name is example.
My name is example.
My name is exa.
My name is mple.
My name is array.
My name is example.
My name is example.
My name is example.
My name is r.
The code will throw an error.
In the following PHP 7.1 program, which of the given code statements should replace ??? to obtain 12345 as output?
<?php
function recursive($var){
echo $var;
if($var < 5){
???
}
}
$a = 1;
recursive($a);
?>
return recursive($var + 1);
recursive($var);
return;
return recursive(+ + $var);
recursive($var++);
return;
Find the output of the following code snippet.
<?php
$bar = <<<'EOF'
1;Anna;eats mangoes
2;Mark;eats apples
EOF;
function bar_parser($bar) {
foreach (explode("\n", $bar) as $I) {
$foo = explode(';', $I);
$id = array_shift($foo);
yield $id => $foo;
}
}
foreach (bar_parser($bar) as $id => $foo) {
echo "$id:\n";
echo" $foo[0]\n";
echo" $foo[1]\n";
}
?>
1; Anna; eats mangoes
2; Mark; eats apples
1:
Anna
eats mangoes
2:
Mark
eats apples
1: Anna;
eats mangoes
2: Mark;
eats apples
Compilation error.
What will be the output of the following PHP 7.1 code?
<?php
$st = 'strike';
echo "At index -4, the character is $st[-4].", PHP_EOL;
$st[-3] = 'o';
echo "Replacement at index -3 to o gives $st.", PHP_EOL;
?>
At index -4, the character is r.
Replacement at index -3 to o gives stroke.
At index -4, the character is r.
Replacement at index -3 to i gives stroke.
At index -4, the character is r.
Replacement at index -3 to o gives o.
The code will throw an error.
What will be the output of the following PHP 7.1 code snippet?
<?php
function xrange($first, $last, $forward = 1)
{ if ($first < $last) {
if ($forward <= 0) {
throw new LogicException('The value of forward should be positive');
}
for ($i = $first; $i <= $last; $i += $forward){
yield $i;
}
} else {
if ($forward >= 0) {
throw new LogicException('The value of forward should be negative');
}
for ($i = $first; $i >= $last; $i += $forward){
yield $i;
}
}
}
echo "\n";
echo 'Output is: ';
foreach (xrange(1, 7, 2) as $num) {
echo "$num";
}
?>
Output is: 1 2 3 4 5 6 7
Output is: 1 7 2
Output is: 1 3 5 7
Compilation error.
In PHP 7.1, which of the following is the correct syntax of the function, Closure::fromCallable, which is used to convert a callable into a closure?
private void Closure Closure::fromCallable ( string new $callable )
public static Closure: :fromCallable ( string $callable)
public static Closure Closure::from Callable ()
public static Closure Closure::fromCallable ( callable $callable )
What will be the output of the following PHP 7.1 code?
<?php
var_dump((bool) -1);
var_dump((bool) 1.5e5);
var_dump((bool) "false");
?>
bool(true)
bool(true)
bool(true)
bool(false)
bool(true)
bool(true)
bool(false)
bool(true)
bool(false)
bool(fa!se)
bool(false)
bool(false)
Rnd the output of the following PHP code.
<?php
$x = array("x" => "Adam", "y" => "Binca");
$y = array("x" => "Avin", "y" => "Beth", "z" => "Chris");
$z = $y + $x;
$x += $y;
var_dump($x);
?>
array(3) {
["x"]=>
string(4) "Adam"
["y"]=>
string(5) "Binca"
["z"]=>
string(5) "Chris"
}
array(3) {
["x"]=>
string(4) "Adam"
["y"]=>
string(4) "Beth"
["z"]=>
string(5) "Chris"
}
array(3) {
["x"]=>
string(4) "Avin"
["y"]=>
string(5) "Binca"
["z"]=>
string(5) "Chris"
}
Compilation error.
Which of the following conditions must be followed by functions that are declared with void as their return type?
i) Omit their return statement.
ii) Use an empty return statement.
Only option i).
Only option ii).
Either option i) or ii).
Neither option i) nor ii).
Rnd the output of the following PHP 7.1 code snippet.
<?php
class Example_Exp extends Exception {}
class Check {
public function checking() {
try {
try {
throw new Example_Exp('Test!');
} catch (Example_Exp $ex)
{ throw $ex;
}
} catch (Exception $ex) {
var_dump($ex->getMessage());
}
}
}
$bar = new check;
$bar->checking();
?>
Test!
string(5) "Test!"
string(5)
Test
Compilation error.
Rnd the output of the following PHP 7.1 code.
<?php
$x = "New ";
$y = $x . "Example ";
echo $y;
$x = "New ";
$x .= "Example ";
echo $x;
?>
New Example
New Example New Example
New Example Example
Example New Example
Compilation error
Find the output of the following PHP 7.1 code.
<?php
$example = function($x) {
return $x * 3;
};
$num = range(2, 6);
$new_num = array_map($example, $num);
print implode(' ', $new_num);
?>
Compilation error.
2 3 4 5 6
18
6 9 12 15 18
In the following PHP 7.1 code, which of the given code statements should replace ??? to print the current year as output in the numeric format, i.e. 2017?
<?php
$date_T = new DateTime();
???
?>
echo (clone($date_T->format('Y')));
echo clone:($date_T)->format('Y');
echo (clone $date_T)->format('Y');
echo clone->($date_T, format:'Y');
echo (clone:$date_T, format'Y');
What will be the output of the following PHP 7.1 code?
<?php
$example = array(2 => 'Two', 4 => 'Four', 6 => 'Six');
unset($example[2]);
$x = array_values($example);
print_r($x);
?>
Array
(
[0] => Two
[1] => Four
[2] => Six
)
Array
(
[0] => Two
[1] => Four
)
Array
(
[0] => Two
[1] => Six
)
Array
(
[0] => Four
[1] => Six
)
Study the given PHP 7.1 code snippet and answer the question that follows.
<?php
$func = function($var)
{
???
};
$func('Example');
$func('Result');
?>
Which of the following statements should replace ??? in the given code to obtain the following output?
Test Example
Test Result
printf("Test", $var);
printf("Test %n\r\n", $var);
printf("Test %r%s\n", $var);
printf("Test %s\r\n", $var);
What will be the output of the following PHP 7.1 code?
<?php
function inverse($a){
if (!$a){
throw new Exception('Division by zero is not allowed.');
}
return 20/$a;
}
try {
echo inverse(8). "\n";
} catch (Exception $ex) {
echo 'Exception caught: ', $ex->getMessage(), "\n";
} finally {
echo "First Example.\n";
}
try {
echo inverse(0). "\n";
} catch (Exception $ex) {
echo 'Exception Caught: ', $ex->getMessage(), "\n";
} finally {
echo "Second Example.\n";
}
echo "Learning PHP\n";
?>
2.5
First Example.
Exception Caught: Division by zero is not allowed.
2.5
First Example.
Exception Caught: Division by zero is not allowed.
Learning PHP
2.5
First Example.
Exception Caught: Division by zero is not allowed.
Second Example.
Learning PHP
Compilation error.
While comparing objects in PHP 7.1, using which of the following operators results in identical object variables, if and only if, they refer to the same instance of the same class?
=
==
===
None of the above.
Which of the following options is an error control operator in PHP 7.1 ?
~
!
@
#
What will be the output of the following PHP code?
<?php
$fruit = "orange";
echo "She likes the juice of fruit Sfruit.".PHP_EOL;
echo "She was asking for the juice of ${fruit}s.".PHP_EOL;
echo "She is very fond of Sfruit fruit juice.";
?>
Notice: Undefined variable: fruit on line 4
She likes the juice of fruit oranges.
She was asking for the juice of s.
She is very fond of orange fruit juice.
Notice: Undefined variable: fruit on line 4
She is very fond of orange fruit juice.
She likes the juice of fruit oranges.
She was asking for the juice of oranges.
She likes the juice of fruit orange.
She was asking for the juice of oranges.
She is very fond of orange fruit juice.
Compilation error in the code.
Which of the given statements is correct about the following PHP 7.1 code?
<?php
class exp {
public $b = <<<'EXAMPLE'
b
EXAMPLE;
}
?>
The code will not compile and will throw an error.
The code will compile but will not print anything on the output screen.
The code will compile and will print EXAMPLE.
The code will compile and will print the following:
EXAMPLE
b
Which of the given code statements should replace ??? in the following PHP 7.1 code snippet, so that 7, 6, 5, 4, is printed as output?
<?php
function &example() {
$var = 8;
while ($var > 4) {
yield $var;
}
}
???
}
?>
foreach (example() as &$num) {
echo (--$num).', ';
foreach (num as &$example()) {
echo ($num--).', '
foreach (example() as $&num) {
echo ($num--).', ';
foreach (example() as $num) {
echo ($--num).', ';
Find the output of the following PHP 7.1 code snippet.
<?php
class Example {
public const ONE = 'one';
private const TWO = 'two';
}
echo Example::ONE, PHP_EOL;
echo Example::TWO, PHP_EOL;
?>
twoone
one
Fatal error
one
two
two
Fatal error
What is the scope of a constant in PHP 7.1 ?
Local
Global
Find the output of the following PHP 7.1 program.
<?php
function double($test)
{
return $test*2;
}
$bar = $ar = 5;
$s = $ar++;
$exp = $dp = ++$bar;
$foo = double($dp++);
$gh = double(++$exp);
$res = $gh += 10;
print_r($res)
?>
10
24
30
N output.
Compilation error.
In relation to PHP 7.1 method overloading, which of the following methods is triggered when inaccessible methods are invoked in an object context?
__call()
__set()
__callstaticO
None of the above.
Find the output of the following PHP 7.1 code.
<?php
function multiple(int $x, int $y)
{ return $x * $y;
}
var_dump(multiple(3, 2));
var_dump(multiple(2.5, 5.5));
?>
int(6)
Fatal error
int(6)
int(14)
int(6)
int(10)
Compilation error.
What will be the output of the following PHP 7.1 code?
<?php
echo 'Mark told Nina that "I\'II see you later"';
echo 'This is an example: \n a newline';
?>
Mark told Nina that "I'II see you later"This is an example: \n a newline
Mark told Nina that "I'II see you later"
This is an example:
a newline
Mark told Nina that "IVII see you later'This is an example:
a newline
The code will return an error.
While working in PHP 7.1, in which of the following types of syntax, a string is delimited with operator, <<<?
nowdoc
heredoc
In both a and b.
Neither in a nor in b.
Which of the following code snippets will print the output, Example?
<?php
namespace Example;
echo '"__NAMESPACE__"';
?>
<?php
namespace Example;
echo '"',__NAMESPACE__,'"';
?>
<?php
namespace Example
echo $"__NAMESPACE__";
?>
None of these
Find the output of the following code.
<?php
trait Example {
public function myFunction() {
echo 'Learning PHP';
}
}
class ABC {
public function myFunction() {
use Example;
echo 'Hello PHP!';
}
}
$obj = new ABC();
$obj->myFunction();
?>
Learning PHP
Hello PHP!
Learning PHP!
Hello PHP
The code will give a compilation error.
As an alternative to an existing list() syntax in PHP 7.1, which of the following options can be used to de-structure arrays for assignments (including within foreach)?
{()}
([])
{[]}
[{}]
In PHP 7.1, which of the following statements is/are correct about generators?
i) With generators, less code is required to be written as compared to implementing an iterator class.
ii) The same generator can be iterated over multiple times.
Only option i).
Only option ii).
Both options i) and ii).
Neither option i) nor ii).
Which of the following is the correct magical PHP constant that is used to determine the current line number of a file?
LINE_ _NUMBER
_ _LINE_ _
_ _CURRENT_ _LINE_ _
_LINE_
Find the output of the following PHP 7.1 code.
<?php
var_dump(round(35/6));
?>
int(6)
int(5)
float (6)
It will return an error.
What will be the output of the following PHP 7.1 code?
<?php
$o = (object) array('5' => 'example');
var_dump(isset($o-> {'5'}));
var_dump(key($o));
?>
bool(false)
int(5)
bool(true)
string(1) "5"
bool(true)
int(5)
bool(false)
string(1) "5"
In PHP 7.1, which of the following options can be used as a default value for parameters that are declared as iterable?
Null
Integer
Array
Float
Which of the following statements is NOT correct about PHP 7.1 variables?
Variable names are case-insensitive.
A variable name must start with a letter or an underscore.
In PHP 7.1, $this is a special variable and cannot be assigned to a new variable.
By default, variables are always assigned by value.
In the following PHP 7.1 code snippet, commenting or removing which code line will result in the successful compilation of the code?
1. <?php
2. namespace X\Y\Z;
3. class Exception extends \Exception {}
4. $x = new Exception('hi');
5. $y = new \Exception('hi');
6. $z = new ArrayObject;
7. ?>
Line 3
Line 4
Line 5
Line 6
What will be the output of the following PHP 7.1 code?
<?php
$example = true;
example_y();
if ($example){
function example_x()
{
echo "PHP\n";
}
}
if ($example)example_x();
function example_y()
{
echo "Example\n";
}
?>
Example
PHP
Example
Example
PHP
PHP
PHP
What will be the output of the following PHP 7.1 code?
<?php
declare(ticks=1);
function t_handler()
{
echo "Example function\n";
}
register_tick_function('t_handler');
$x = 1;
if ($x > 0) {
$x += 2;
print($x);
}
?>
3Example function
Example function
3
Example function
Example function
Example function
3
Example function
Example function
Example function
3Example function
What will be the output of the following PHP code?
<?php
interface Exp { public function x();}
class First implements Exp {
public function x() {}
}
class Second {}
function x(Exp $e){
echo get_class($e)."\n";
}
x(new First);
x(new Second);
?>
The code will compile successfully but will not print anything.
First Fatal error
First Second
Second First
In PHP 7.1, which of the following is the correct syntax for a function with iterable generator return type?
<?php
function iterable example(){
yield 1;
yield 2;
yield 3;
}
?>
<?php
function example(): iterable {
yield 1;
yield 2;
yield 3;
}
?>
<?php
function example(): iterable {
yield (1,2,3);
}
?>
<?php
function iterable example)
yield (1,2,3);
)
?>
In PHP 7.1, under which of the following types of scenarios, a TypeError may be thrown?
i) When the argument type, which is being passed to a function, does not match its corresponding declared parameter type.
ii) When the returned value from a function does not match the declared function return type.
iii) When an invalid number of arguments are passed to a built-in PHP function.
Only option i).
Only option ii).
Only options i) and iii).
All options i), ii) and iii).
What will be the output of the following PHP 7.1 code snippet?
<?php
class Red {
public static function b_func() {
static::a_func();
}
public static function a_func() {
echo "Colour is ",__CLASS__."\n";
}
}
class Blue extends Red {
public static function run() {
Red::b_func();
parent ::b_func();
self::b_func();
}
public static function a_func() {
echo "Colour is ",__CLASS__."\n";
}
}
class Green extends Blue {
public static function a_func() {
echo "Colour is ",__CLASS__."\n";
}
}
Green::run();
?>
Colour is Red
Colour is Blue
Colour is Green
Colour is Red
Colour is Red
Colour is Green
Colour is Red
Colour is Green
Colour is Green
Colour is Red
Colour is Red
Colour is Red
Compile time error.
Find the output of the following PHP code.
<?php
$string = 'example';
echo "The output for '$string' is '$string[-1]'.\n";
?>
The output for 'example' is 'NULL'.
The output for 'example' is 'e'.
The output for 'example' is 'example'.
Compilation error.
Runtime error.
While creating or modifying an array in PHP 7.1, what will happen if an empty index operator is applied on a string?
The string will be converted into an array.
The string will be converted into an integer.
It will throw a fatal error.
None of the above is correct.
In PHP 7.1, which of the following is the correct syntax of the is_iterable() function, which is used to verify whether or not the content of a variable is an iterable value?
bool is_iterable (mixed $var)
int is_iterable ($var)
sting is_iterable ( mixed $var, time $time)
bool is_iterable (string prefix, mixed $var)
In PHP 7.1, which of the following operators are non-associative?
&&
==
??
<>
In PHP 7.1, which of the following options can be used to mark the type declarations for parameters and return values as nullable, by prefixing the type name?
Dollar sign ($)
Ampersand sign (&)
Question mark (?)
Percentage sign (%)
In relation to PHP array cast, Booleans can be cast to which of the following options?
String
Intege
Array
Float
On compilation, the following PHP 7.1 code was supposed to produce the output 24. However, the code contains errors. Identify the code lines with errors.
1. <?php
2.
3. class example
4. {
5. public $foo;
6.
7. public function __construct() {
8. $this->function = foo() {
9. return 24;
10. };
11. }
12. }
13. $exp = new example();
14. echo ($exp->function)(), PHP_EOL;
Line 5
Line 7
Line 8
Line 13
Line 14
What will be the output of the following PHP 7.1 code snippet?
-<?php
abstract class A_Class
{
abstract protected function name_P($name);
}
class Example extends A_Class
{
public function Name_P($name, $separator = ".") {
if ($name == "Mango") {
$product = "Fruit";
} elseif ($name == "Carrot") {
$product = "Vegitable";
} else {
$product ="";
}
return "{$name}{$separator} {$product}";
}
}
$class = new Example;
echo $class->Name_P("Mango"), "\n";
echo $class->Name_P("Carrot"), "\n";
?>
-Mango. Fruit
Carrot. Vegitable
-Mango.
Carrot
-Mango. Fruit
Carrot
Compilation error.
What will be the output of the following PHP code?
<?php
var_dump("pqrstu"[-2]);
var_dump(strpos("ppqqrr","q", -3)); ?>
string(1) "t"
int(3)
int(-3)
string("s")
int(2)
The code will throw an error.
In relation to PHP 7.1 global space, prefixing a name with which of the following options specifies that the name is required from the global space even in the context of the namespace?
\
/
&
@
Carefully analyze the following program.
1.<?php
2.class example
3.{
4.static function check()
5.{
6.echo "Check\n";
7.}
8.function test()
9.{
10.echo "Test\n";
11.}
12.}
13.$f = new array("example", "check"); исправил:) $f = array( new example, "check");
14.$f();
15.$f = array(new example, test); исправил:) $f = array(new example, "test");
16.$f();
17.$f = "example::check";
18.$f();
19.?>
The given program was supposed to produce the following output on execution.
Check
Test
Check
However, the program contains errors. Identify the line numbers that contain errors.
Line 4
Line 13
Line 15
Line 17
In relation to PHP 7.1 throwable interface, which of the following options is used for getting a string representation of a thrown object?
Throwable::__toString
Throwable::getPrevious
Throwable::getTrace
None of the above.
Which of the given statements is correct about the following PHP 7.1 code?
<?php
function example()
{
static $cnt = 0;
$cnt++;
echo $cnt;
if ($cnt < 5) {
example();
}
$cnt--;
}
?>
The code will compile successfully and will print the following output:
1 2 3 4 5
The code will compile successfully and will print the following output:
5 4 3 2 1 0
The code will compile successfully but will not print any output.
The code will not compile.
Which of the following is the correct syntax of the PHP 7.1 magic method, __Sleep()?
public array __sleep ( void )
void __sleep ( void )
protected string__sleep ( array )
public void__sleep ( string )
Find the output of the following PHP 7.1 code.
example.php
<?php
$x = 'PHP';
return $x;
?>
nexample.php
<?php
$x = 'PHP';
?>
testexample.php
<?php
$var1 = include 'example.php';
echo $var1;
$var2 = include 'nexample.php';
echo $var2;
?>
PHP
example.php o nexample.php
1
Compilation error.
None of the above.
What will be the output of the following PHP code?
<?php
echo '-Result-' . PHP_EOL;
$x = 'D7';
for ($i=0; $i<5; $i++) {
echo ++$x . PHP_EOL;
}
?>
-Result-
D8
D9
D10
D11
D12
-Result-
D8
E9
F0
G1
H2
-Result-
D8
D9
E0
E1
E2
Compilation error.
Find the output of the following PHP 7.1 code.
<?php
$example = array(
5 => "e",
"5" => "f",
5.5 => "g",
true => "i",
);
var_dump($example);
?>
array(2) {
[5]=>
string(1) "f"
[5]=>
string(2) "i"
}
array(2) {
[5]=>
string(1) "e"
[1]=>
string(1) "f"
}
array(2) {
[5]=>
string(1) "g"
[1]=>
string(1) "i”
}
array(2) {
[5]=>
string(1) "e"
[5.5]=>
string(1) "g"
}
In PHP 7.1, which of the following is the correct syntax of the session_gc() function, which is used to perform session data garbage collection?
int session_gc (void )
void session_gc (void)
string session_gc (void )
void session_gc (time)
Which of the given statements is correct about the following PHP 7.1 code snippet?
<?php
$x = 2.98765431;
$y = 2.98765430;
$epsilon = 0.00001; if(abs($x-$y) < $epsilon) {
echo "true";
}
?>
The code will not compile.
Tiie code will compile but will not print any output.
The code will compile and will print NAN.
The code will compile and will print true.
void session_gc (time)
Which of the following options are used for specifying a string literal in PHP 7.1?
i) Single quotes
ii) Double quotes
iii) heredoc syntax
iv) now doc syntax
Only options i) and ii).
Only options i) and iv).
Only options i), ii) and iii).
All options i), ii), iii) and iv).
PHP 7.1 Skills Test Fiverr 2020