dalecosp you might not like what else ol' Zardoz has to say...
Today I learned
TIL that the film 'Lawrence of Arabia' had its world premiere 10 years closer to the start of the Great War than to the current day.
dalecosp and Rampling, for all her modern foibles, was something to behold.
TIL that returning false
works if you declare return type int:
function foo() : int {
return false;
}
var_dump(foo());
the result:
int(0)
but returning NULL
from an int function throws an exception:
function foo() : int {
return null;
}
var_dump(foo());
the result:
PHP Fatal error: Uncaught TypeError: Return value of foo() must be of the type integer, null returned in /tmp/a.php:3
Stack trace:
#0 /tmp/a.php(5): foo()
#1 {main}
thrown in /tmp/a.php on line 3
- Edited
You'll also get that if you try to return a non-numeric string (a numeric string would be recast).
Also, attempting to return anything other than an int fail if you declare(strict_types=1);
.
Returning null is hazardous, and equivalent to returning nothing at all (return null;
is identical in meaning to return;
; if a function is supposed to return a value, return;
looks wrong). If for some reason you do want nulls hanging around, you can declare the possibility as function foo(): ?int
.
Today I learned Mira Furlan is dead, this year sucks let's go to 2022
TIL that the U.S. Government website for reporting online crime does not work:
curl -v https://www.ic3.gov/complaint/default.aspx
* Trying 65.201.175.169:443...
* TCP_NODELAY set
* Trying 2600:803:c20::3:16:443...
* TCP_NODELAY set
* Immediate connect fail for 2600:803:c20::3:16: Network is unreachable
* Trying 2600:803:c20::3:15:443...
* TCP_NODELAY set
* Immediate connect fail for 2600:803:c20::3:15: Network is unreachable
* Trying 2600:803:c20::3:16:443...
* TCP_NODELAY set
* Immediate connect fail for 2600:803:c20::3:16: Network is unreachable
* Trying 2600:803:c20::3:15:443...
* TCP_NODELAY set
* Immediate connect fail for 2600:803:c20::3:15: Network is unreachable
- Edited
Today I learned PHP filters. I really enjoy the PHP language while I am learning it.
TIL (thanks to sneakyimp) that you can do...
16:16 $ /usr/bin/php -a
Interactive shell
php > $
= 'happy';
php > echo $
;
happy
php >
you can define emoji classes and namespaces, too:
class
{
public static function
(){
echo "
\n";
}
}
::
();
- Edited
Today i learned how to register here!
Today I learned how to turn my old laptop into a server at home
cluelessPHP linux?
sneakyimp Running it on windows machine
Today I learned to set up virtual machines and pint to different projects
Okay, so array_map(null, $array1, $array2, $array, ...)
can be used to zip several arrays together. array_map(null, [1,2,3], [4,5,6]) == [[1,4], [2,5], [3,6]]
. And then you've got the destructuring operator "...
" and now you can have a general array-transpose operation:
$array = [[1,2,3], [4,5,6], [7,8,9]];
array_map(null, ...$array) == [[1,4,7], [2,5,8], [3,6,9]];
Which is all well, and good. But TIL:
array_map(null, ...[[a,b,c], [d,e,f], [g,h,i], [j,k,l]]) == [[a,d,g,j], [b,e,h,k], [c,f,i,l]]
array_map(null, ...[[a,b,c], [d,e,f], [g,h,i]]) == [[a,d,g], [b,e,h], [c,f,i]]
array_map(null, ...[[a,b,c], [d,e,f]]) == [[a,d], [b,e], [c,f]]
array_map(null, ...[[a,b,c]]) == [a, b, c]
4 arrays of 3 elements each becomes 3 arrays of 4 elements each
3 arrays of 3 elements each becomes 3 arrays of 3 elements each
2 arrays of 3 elements each becomes 3 arrays of 2 elements each
1 array of 3 elements each becomes 1 array of 3 elements each
One of these things is not like the others. And apparently it's not a bug. array_map(null, ...[[a,b,c]])
is equivalent to array_map(null, [a,b,c])
as it should be, but it was decided that the latter should be a no-op and just return its second argument unchanged.
if(!is_array($new_array[0])) {
$new_array = [$new_array];
}
(It's been years since I touched array_map()
-- thankfully? -- and have never run into that syntax, and kind of hope I never have a reason to use it. )
NogDog
You don't like functional programming?
Weedpacket You don't like functional programming?
Not a question of like/dislike, but more that I've not pursued it, other than reading/viewing a few high-level discussions at mainly theoretical levels -- no practical experience (intentionally) implementing it.