-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.php
More file actions
69 lines (57 loc) · 1.8 KB
/
types.php
File metadata and controls
69 lines (57 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/*
* Copyright (C) 2024-2026 Katarzyna Krasińska
* PHP.lab - https://github.com/katheroine/php.lab
* Licensed under GPL-3.0 - see LICENSE.md
*/
$n = null;
$b = true;
$i = 5;
$d = 2.4;
$s = "hello";
$a = [3, 5, 7];
$h = [
2 => "Hello, there!",
'color' => 'orange',
3.14 => 'PI',
];
$u = function(int $number) {
return $number * 3;
};
$o = (object) [
2 => "Hello, there!",
'color' => 'orange',
3.14 => 'PI',
];
$co = new class {
private int $number;
public function set_number(int $number): void {
$this->number = $number;
}
public function get_number(): int {
return $this->number;
}
};
echo "\$n = null; // null: " . $n . " (" . gettype($n) . ")\n\n";
echo "\$b = true; // boolean: " . $b . " (" . gettype($b) . ")\n\n";
echo "\$i = 5; // integer: " . $i . " (" . gettype($i) . ")\n\n";
echo "\$d = 2.4; // floating point double precision: " . $d . " (" . gettype($d) . ")\n\n";
echo "\$s = \"hello\"; // string: " . $s . " (" . gettype($s) . ")\n\n";
echo "\$a = [3, 5, 7]; // array:\n";
print_r($a);
echo "(" . gettype($a) . ")\n\n";
echo "\$h = [\n 2 => \"Hello, there!\",\n 'color' => 'orange',\n 3.14 => 'PI',\n];\n// hash:\n";
print_r($h);
echo "(" . gettype($h) . ")\n\n";
echo "\$u = function(int \$number) {\n return number * 3;\n};\n// function:\n";
print_r($u);
echo "(" . gettype($u) . ")\n\n";
echo "\$o = (object) [ 2 => \"Hello, there!\",\n 'color' => 'orange',\n 3.14 => 'PI',\n];\n// object (created from hash):\n";
print_r($o);
echo "(" . gettype($o) . ")\n\n";
echo "\$co = new class {\n private int \$number;
public function set_number(int \$number): void {\n \$this->number = \$number;\n }
public function get_number(): int {\n return \$number;\n }\n};
// object (created from anonymous class):\n";
print_r($co);
echo "(" . gettype($co) . ")\n\n";