aboutsummaryrefslogtreecommitdiffhomepage
path: root/quiz.php
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2022-12-27 20:52:31 +0900
committernsfisis <nsfisis@gmail.com>2023-02-21 08:59:48 +0900
commitb0ad59f3c3abf2fe25d7163c6d29711ab652deb0 (patch)
treee7a1ce1c00dbb2be0b58f77478661cd0063e5663 /quiz.php
parent90b6f69001806e8806d15d807d6bdd1f8c12207d (diff)
downloadPHPerKaigi2023-slide-b0ad59f3c3abf2fe25d7163c6d29711ab652deb0.tar.gz
PHPerKaigi2023-slide-b0ad59f3c3abf2fe25d7163c6d29711ab652deb0.tar.zst
PHPerKaigi2023-slide-b0ad59f3c3abf2fe25d7163c6d29711ab652deb0.zip
スライドを作成
Diffstat (limited to 'quiz.php')
-rw-r--r--quiz.php81
1 files changed, 81 insertions, 0 deletions
diff --git a/quiz.php b/quiz.php
new file mode 100644
index 0000000..f68e766
--- /dev/null
+++ b/quiz.php
@@ -0,0 +1,81 @@
+<?php
+
+declare(strict_types=1);
+
+####################################
+# Q1
+
+$x = 1;
+$y =& $x;
+$y = 2;
+echo "x = $x", PHP_EOL;
+// => 2
+echo "y = $y", PHP_EOL;
+// => 2
+
+####################################
+# Q2
+
+$x = 1;
+$y =& $x;
+$z = $y;
+$z = 2;
+echo "x = $x", PHP_EOL;
+// => 1
+echo "y = $y", PHP_EOL;
+// => 1
+echo "z = $z", PHP_EOL;
+// => 2
+
+####################################
+# Q3
+
+$xs = [1, 2];
+$x =& $xs[0];
+$x = 42;
+echo "x = $x", PHP_EOL;
+// => 42
+echo "xs = [$xs[0], $xs[1]]", PHP_EOL;
+// => [42, 2]
+
+####################################
+# Q4
+
+$xs = [1, 2];
+$x =& $xs[0];
+$ys = $xs;
+$x = 42;
+$ys[1] = 3;
+echo "x = $x", PHP_EOL;
+// => 42
+echo "xs = [$xs[0], $xs[1]]", PHP_EOL;
+// => [42, 2]
+echo "ys = [$ys[0], $ys[1]]", PHP_EOL;
+// => [42, 3]
+
+####################################
+# Q5 (割愛)
+
+$g = 1;
+function f(&$x) {
+ $x =& $GLOBALS['g'];
+}
+$y = 0;
+f($y);
+$y = 42;
+echo "y = $y", PHP_EOL;
+// => 42
+echo "g = $g", PHP_EOL;
+// => 1
+
+####################################
+# Q6 (割愛)
+
+class C {
+ public int $x = 1;
+}
+$c = new C();
+$y =& $c->x;
+$y = 'PHPerKaigi';
+// => Fatal error: TypeError
+// Cannot assign string to reference held by property C::$x of type int