Rules
▸ 3 Rounds
▸ Qualification Round
▸ Main Round
▸ Final Round
▸ Runtime is PHP 7.0/7.1
▸ Don’t cheat! (no mobile devices)
▸ Be fair
Slide 5
Slide 5 text
LET’S START
Slide 6
Slide 6 text
ROUND 1
QUALIFICATION
Slide 7
Slide 7 text
Round 1 - Qualification
▸ Take a quiz
▸ Take a pen
▸ Answer the 5 questions (single choice)
▸ Hand the quiz to us
▸ Have a beer & wait for the next round
Slide 8
Slide 8 text
No content
Slide 9
Slide 9 text
QUESTION 1
What is the output of this code snippet?
$a = 4;
echo $a++ + $a++;
8
A
10
C 11
D
9
B
Slide 10
Slide 10 text
QUESTION 1
What is the output of this code snippet?
$a = 4;
echo $a++ + $a++;
8
A
10
C 11
D
9
B
Slide 11
Slide 11 text
QUESTION 2
What is the output of this code snippet?
var_dump(true ? 'Foo' : false ? 'Bar' : 'Baz');
string(3) Foo
A
bool(false)
C string(3) Baz
D
string(3) Bar
B
Slide 12
Slide 12 text
QUESTION 2
What is the output of this code snippet?
var_dump(true ? 'Foo' : false ? 'Bar' : 'Baz');
string(3) Foo
A
bool(false)
C string(3) Baz
D
string(3) Bar
B
Slide 13
Slide 13 text
QUESTION 3
What is the output of this code snippet?
$x = 0;
echo 'Hello ' . $x+42 . ' World';
Fatal Error
A
Hello 43
C
Hello 42 World
D 42 World
B
Slide 14
Slide 14 text
QUESTION 3
What is the output of this code snippet?
$x = 0;
echo 'Hello ' . $x+42 . ' World';
Fatal Error
A
Hello 43
C
Hello 42 World
D 42 World
B
Slide 15
Slide 15 text
QUESTION 4
What is the output of this code snippet?
$versions = ['7.1', '7.2', '7.3'];
var_dump(in_array('7.10', $versions));
bool(true)
A bool(false)
B
Slide 16
Slide 16 text
QUESTION 4
What is the output of this code snippet?
$versions = ['7.1', '7.2', '7.3'];
var_dump(in_array('7.10', $versions));
bool(true)
A bool(false)
B
Slide 17
Slide 17 text
QUESTION 5
Which array key will be overridden?
0234
A
'0'
B
'test'
C
234
D
$array = [
'test' => 'foo',
'0' => 'baz',
0234 => 'x',
234 => 'y',
'0234' => 'bar',
'234' => 'omg',
'0.0' => 'yeah'
];
Slide 18
Slide 18 text
QUESTION 5
Which array key will be overridden?
0234
A
'0'
B
'test'
C
234
D
$array = [
'test' => 'foo',
'0' => 'baz',
0234 => 'x',
234 => 'y',
'0234' => 'bar',
'234' => 'omg',
'0.0' => 'yeah'
];
Slide 19
Slide 19 text
ROUND 2
MAIN ROUND
Slide 20
Slide 20 text
QUESTION 6
What is the output of this code snippet?
echo(print('hello'));
hellohello
A
hello1
C empty output
D
hello
B
Slide 21
Slide 21 text
QUESTION 6
What is the output of this code snippet?
echo(print('hello'));
hellohello
A
hello1
C empty output
D
hello
B
Slide 22
Slide 22 text
QUESTION 7
What is the output of this code snippet?
$max = (int)(float)PHP_INT_MAX;
var_dump($max + PHP_INT_MAX);
int(-1)
A
int(-9223372036854775808)
C int(0)
D
double(1.844674407371E+19)
B
Slide 23
Slide 23 text
QUESTION 7
What is the output of this code snippet?
$max = (int)(float)PHP_INT_MAX;
var_dump($max + PHP_INT_MAX);
int(-1)
A
int(-9223372036854775808)
C int(0)
D
double(1.844674407371E+19)
B
Slide 24
Slide 24 text
QUESTION 8
What is the output of this code snippet?
list($a, $a) = array(1, 2, 3, 4);
var_dump($a);
Fatal error
A
int(1)
C int(2)
D
int(4)
B
Slide 25
Slide 25 text
QUESTION 8
What is the output of this code snippet?
list($a, $a) = array(1, 2, 3, 4);
var_dump($a);
Fatal error
A
int(1)
C int(2)
D
int(4)
B
BTW: BC BREAK OF PHP 7
Slide 26
Slide 26 text
QUESTION 9
What is the output of this code snippet?
$array = [
5076964154930102272 => 2,
999999999999999999999999999999 => 4,
];
var_dump(array_sum($array));
int(6)
A
int(2)
C int(-2)
D
int(4)
B
Slide 27
Slide 27 text
QUESTION 9
What is the output of this code snippet?
$array = [
5076964154930102272 => 2,
999999999999999999999999999999 => 4,
];
var_dump(array_sum($array));
int(6)
A
int(2)
C int(-2)
D
int(4)
B
Slide 28
Slide 28 text
QUESTION 10
What is the output of this code snippet?
$array = [1, 2, 3];
foreach ($array as &$v) {}
foreach ($array as $v) {}
echo implode(',', $array);
1,1,1
A
1,2,2
C 3,3,3
D
1,2,3
B
Slide 29
Slide 29 text
QUESTION 10
What is the output of this code snippet?
$array = [1, 2, 3];
foreach ($array as &$v) {}
foreach ($array as $v) {}
echo implode(',', $array);
1,1,1
A
1,2,2
C 3,3,3
D
1,2,3
B
Slide 30
Slide 30 text
QUESTION 11
What is the output of this code snippet?
function compare($a, $b, $c) {
echo (int)($a < $b);
echo (int)($b < $c);
echo (int)($c < $a);
}
compare('066', '07x', '28');
010
A
111
C 001
D
110
B
Slide 31
Slide 31 text
QUESTION 11
What is the output of this code snippet?
function compare($a, $b, $c) {
echo (int)($a < $b);
echo (int)($b < $c);
echo (int)($c < $a);
}
compare('066', '07x', '28');
010
A
111
C 001
D
110
B
Slide 32
Slide 32 text
QUESTION 12
What is the output of this code snippet?
namespace Foo { class Bar { } }
namespace { echo(Bar::class); }
Bar
A
Fatal Error
C empty output
D
Foo\Bar
B
Slide 33
Slide 33 text
QUESTION 12
What is the output of this code snippet?
namespace Foo { class Bar { } }
namespace { echo(Bar::class); }
Bar
A
Fatal Error
C empty output
D
Foo\Bar
B
Slide 34
Slide 34 text
QUESTION 13
What is the output of this code snippet?
function foo() {
try { return 1337; }
finally { return 42; }
}
var_dump(foo());
int(1337)
A
string(6) 133742
C int(42)
D
Fatal Error
B
Slide 35
Slide 35 text
QUESTION 13
What is the output of this code snippet?
function foo() {
try { return 1337; }
finally { return 42; }
}
var_dump(foo());
int(1337)
A
string(6) 133742
C int(42)
D
Fatal Error
B
Slide 36
Slide 36 text
QUESTION 14
What is the output of this code snippet?
$nan = NAN;
var_dump(0 < NAN);
var_dump(0 < $nan);
bool(true)
bool(true)
A
bool(true)
bool(false)
C bool(false)
bool(false)
D
bool(false)
bool(true)
B
Slide 37
Slide 37 text
QUESTION 14
What is the output of this code snippet?
$nan = NAN;
var_dump(0 < NAN);
var_dump(0 < $nan);
bool(true)
bool(true)
A
bool(true)
bool(false)
C bool(false)
bool(false)
D
bool(false)
bool(true)
B
IT’S A BUG - FIXED WITH 7.2
Slide 38
Slide 38 text
QUESTION 15
What is the output of this code snippet?
$objects = [new \stdClass()];
var_dump(in_array((object)[], $objects));
bool(true)
A bool(false)
B
Slide 39
Slide 39 text
QUESTION 15
What is the output of this code snippet?
$objects = [new \stdClass()];
var_dump(in_array((object)[], $objects));
bool(true)
A bool(false)
B
Slide 40
Slide 40 text
ROUND 3
FINAL
Slide 41
Slide 41 text
QUESTION 16
What is the output of this code snippet?
echo(printf('hello'));
Slide 42
Slide 42 text
QUESTION 16
What is the output of this code snippet?
echo(printf('hello'));
hello5
Slide 43
Slide 43 text
QUESTION 17
What is the output of this code snippet?
$date1 = new DateTimeImmutable(
'2017-10-29',
new DateTimeZone('Europe/Berlin')
);
$date2 = $date1->modify('+2 hours');
echo $date1->diff($date2)->format('%h');
Slide 44
Slide 44 text
QUESTION 17
What is the output of this code snippet?
$date1 = new DateTimeImmutable(
'2017-10-29',
new DateTimeZone('Europe/Berlin')
);
$date2 = $date1->modify('+2 hours');
echo $date1->diff($date2)->format('%h');
3
Slide 45
Slide 45 text
QUESTION 18
Which number is displayed?
use const true as false;
if (false) { echo 1; }
if (true) { echo 2; }
if (true === false) { echo 3; }
if (\false) { echo 4; }
if (\true) { echo 5; }
if (2 > 1) { echo 6; }
Slide 46
Slide 46 text
QUESTION 18
Which number is displayed?
use const true as false;
if (false) { echo 1; }
if (true) { echo 2; }
if (true === false) { echo 3; }
if (\false) { echo 4; }
if (\true) { echo 5; }
if (2 > 1) { echo 6; }
12356
Slide 47
Slide 47 text
QUESTION 19
Which string is displayed?
class Foo {
public $bar = 'baz';
static function create() {
$foo = new self();
$foo->bar .= 'baz';
$foo->foo();
return $foo;
}
private function foo() {
$this->bar .= 'bar';
}
}
$foo = Foo::create();
echo $foo->bar;
Slide 48
Slide 48 text
QUESTION 19
Which string is displayed?
bazbarbazbar
class Foo {
public $bar = 'baz';
static function create() {
$foo = new self();
$foo->bar .= 'baz';
$foo->foo();
return $foo;
}
private function foo() {
$this->bar .= 'bar';
}
}
$foo = Foo::create();
echo $foo->bar;
Slide 49
Slide 49 text
QUESTION 20
What is the output of file2.php?
// file1.php
$a = 1;
$b = 1;
var_dump($a + $b);
// file2.php
$b = new class {
function __destruct(){
$GLOBALS['b'] = 2;
}
};
require 'file1.php';
Credits: Nikita Popov - Static Optimization of PHP Bytecode
Slide 50
Slide 50 text
QUESTION 20
What is the output of file2.php?
// file1.php
$a = 1;
$b = 1;
var_dump($a + $b);
// file2.php
$b = new class {
function __destruct(){
$GLOBALS['b'] = 2;
}
};
require 'file1.php';
int(3)
Credits: Nikita Popov - Static Optimization of PHP Bytecode