-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1212.php
More file actions
32 lines (26 loc) · 964 Bytes
/
1212.php
File metadata and controls
32 lines (26 loc) · 964 Bytes
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
<?php
// When you add declare(strict_types=1); at the top of your PHP file, PHP enforces strict type checking, but only for function arguments and return types. It does not apply to implicit type conversion during operations like addition. So, in this specific case, type juggling will still occur, and the addition will work as you saw.
declare (strict_types = 1);
$temp1 = "2.3";
$temp2 = 3.2;
$temp = $temp1 + $temp2;
var_dump($temp1);
var_dump($temp2);
var_dump($temp);
// If I remove declare statement, it will do math operation and return int value as 4.
function tempFun(string $arg1): int
{
var_dump($arg1);
return $arg1 + 2.2;
}
// echo tempFun("2.3");
// Anonymous fn
$tempFun2 = function () use ($temp2) {
return 5 + $temp2;
};
// echo $tempFun2();
// Arrow fn
// We can avoide use statement in anonymous fn if we use arrow fn syntext. Otherwise all arrow fn are anonymous fn.
$simpleSum2 = fn() => 10 + $temp2;
echo $simpleSum2();
s