TIL (about the Dark Arts of HTML)
-
TIL why the setup guides for various Linuxy solutions include "2>&1" in their cron job command invocations.
-
TIL
http://i.imgur.com/sYWszlU.mp4
All scorpions fluoresce under ultraviolet light, such as a black light or natural moonlight. The blue-green glow comes from a substance found in the hyaline layer, a very thin but super tough coating in a part of the scorpion's exoskeleton called the cuticle
-
Did you now? how fascinating.
-
I repeat myself, but... TIL @accalia's browser does not support HTML5 video.
-
@Zecc said in TIL (about the Dark Arts of HTML):
I repeat myself, but... TIL @accalia's browser does not support HTML5 video.
ORLY?
-
TIL:
I like bluegrass music.
https://www.youtube.com/watch?v=B9FzVhw8_bY
https://www.youtube.com/watch?v=forqmom3YuY
-
TIL about the Nintendo Playstation
-
@Yamikuronue said in TIL (about the Dark Arts of HTML):
TIL about the Nintendo Playstation
I want one
-
So I (kinda stupidly) tried to check if
json_decode
in PHP returned a valid result today. I did this:if(count($json_array)) { ...
Now do note that
json_decode
returnsfalse
on failure so... you'd expect an error if you feedfalse
tocount()
, right?php > var_dump(count(false)); int(1)
Ummm... wait... check the docs...
int count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )
So, TIL that booleans are countable in PHP. Both
count(true)
andcount(false)
return... 1.Just out of curiosity, I went to check what
empty()
does:php > var_dump(empty(true)); bool(false) php > var_dump(empty(false)); bool(true)
-
@Onyx said in TIL (about the Dark Arts of HTML):
php > var_dump(empty(true)); bool(false) php > var_dump(empty(false)); bool(true)
I tried to understand it, and this is what my brain did:
-
@Onyx said in TIL (about the Dark Arts of HTML):
Just out of curiosity, I went to check what empty() does
What were you expecting? Looking at the documented return values, the only input argument considered empty that makes me feel uneasy is the string "0".
-
@RaceProUK said in TIL (about the Dark Arts of HTML):
I tried to understand it, and this is what my brain did:
php > var_dump(empty(true)); bool(false)
Is
true
empty? Nope.php > var_dump(empty(false)); bool(true)
Is
false
empty? Yep.
-
@Zecc said in TIL (about the Dark Arts of HTML):
What were you expecting?
PHP Error: WTF dude? on line 1
Also, if something has a count of 1, how is it empty? The only thing that seems valid and makes sense:
php > var_dump(count(null)); int(0) php > var_dump(empty(null)); bool(true)
Although I'd still prefer errors on both.
-
@Zecc said in TIL (about the Dark Arts of HTML):
php > var_dump(empty(true)); bool(false)
Is
true
empty? Nope.php > var_dump(empty(false)); bool(true)
Is
false
empty? Yep.
-
I said:
What were you expecting?
Then you said:
PHP Error: WTF dude? on line 1
I see you must be new to PHP.
-
@Zecc I'm just a hopeless optimist...
-
@Onyx So that's how they implement boolean negation!
-
-
@Jaloopa said in TIL (about the Dark Arts of HTML):
@RaceProUK said in TIL (about the Dark Arts of HTML):
That looks so dodgy...
That looks like my kind of fun! :-D
-
@Jaloopa said in TIL (about the Dark Arts of HTML):
That looks so dodgy
And yet it's from a cartoon certified suitable for 8-year-olds :D
-
@RaceProUK said in TIL (about the Dark Arts of HTML):
@Jaloopa said in TIL (about the Dark Arts of HTML):
That looks so dodgy
And yet it's from a cartoon certified suitable for 8-year-olds :D
And yet most fanart seems to be suitable for 18+-years-old.
-
Filed under: Rule 34
-
@Zecc said in TIL (about the Dark Arts of HTML):
@Onyx said in TIL (about the Dark Arts of HTML):
Just out of curiosity, I went to check what empty() does
What were you expecting? Looking at the documented return values, the only input argument considered empty that makes me feel uneasy is the string "0".
I would expect, from a sane language, an error when trying to coerce a non-integer value into a boolean. There is no possible sane behaviour for empty(), especially as a builtin.
I won't deny that it is handy and that I use it extensively myself, though.
-
@cark said in TIL (about the Dark Arts of HTML):
error when trying to coerce a non-integer value into a boolean
I'd be happy with a few other values also being automatically translated, e.g., the string
"true"
going to the booleantrue
…
-
@cark said in TIL (about the Dark Arts of HTML):
I would expect, from a sane language,
Yes, but we were discussing PHP. </mandatory>
-
@dkf Questo funzionerà bene in lingue non inglesi.
-
@RaceProUK
Oui parce-que les languages de programmation qui utilize pas l'anglais sont du merde. Oui je te regarde! Putain de VBA! Quelle idiot pensait que c'était une bonne idee de utiliser le language d'Office dans la programmation VBA! Mon dieu! Horreur! Connard! Fillon!
-
-
@Onyx said in TIL (about the Dark Arts of HTML):
So, TIL that booleans are countable in PHP.
Um, no. The thing that you passed to
count
wasn't an array, wasn't countable, and wasn'tNULL
, so it counted it as 1 thing. It returned 1.The docs specifically state that if you pass in anything that isn't an array or countable object,
count
will return 1, with the sole exception that if you pass inNULL
it will return 0.
-
@Zecc count seems fine, but I would expect "empty" to mean that a variable is actually empty (i.e. not set, or set to NULL).
If I set
x = false
, x is not empty by any common meaning of the word. So at the very least it should have a different name, if there's really a need for this function (isn't it just!bool(x)
?).But then again, it's this sort of general ambiguity on how values are interpreted that makes PHP PHP.
-
@RaceProUK Apples and toranges. "true" is a language keyword, as well as the value you get when you cast a boolean to a st—
php > var_dump("" . true); string(1) "1"
Oh.
-
@anonymous234 it makes sense if you already know what type(s) of data the variable can hold.
If you don't even know what type of data a variable might hold, .
@Zecc said in TIL (about the Dark Arts of HTML):
@RaceProUK Apples and toranges. "true" is a language keyword, as well as the value you get when you cast a boolean to a st—
php > var_dump("" . true); string(1) "1"
Oh.
If you really want a fun surprise, try that with
false
.
-
@Zecc said in TIL (about the Dark Arts of HTML):
@RaceProUK Apples and toranges. "true" is a language keyword, as well as the value you get when you cast a boolean to a st—
php > var_dump("" . true); string(1) "1"
Oh.
Even JavaScript gets this right:
-
@anotherusername said in TIL (about the Dark Arts of HTML):
If you don't even know what type of data a variable might hold, .
Like parsing potentially arbitrary JSON, which might be from a third party service and you aren't sure if it's valid, whether some of the objects have any properties, and are not sure how they are quoting values (are numbers sent as numbers or strings)?
-
@RaceProUK said in TIL (about the Dark Arts of HTML):
Even JavaScript gets this right
For some value of right.
⇒ !!( "" + false) ⇐ true
ie
⇒ Boolean("false") ⇐ true
-
@Onyx said in TIL (about the Dark Arts of HTML):
@anotherusername said in TIL (about the Dark Arts of HTML):
If you don't even know what type of data a variable might hold, .
Like parsing potentially arbitrary JSON, which might be from a third party service and you aren't sure if it's valid, whether some of the objects have any properties, and are not sure how they are quoting values (are numbers sent as numbers or strings)?
The third-party service is probably in that scenario. But someone definitely is. In any case, if you don't know what type of data a variable might hold,
empty
probably isn't a function you should be using with it.
-
@Zecc said in TIL (about the Dark Arts of HTML):
@RaceProUK said in TIL (about the Dark Arts of HTML):
Even JavaScript gets this right
For some value of right.
⇒ !!( "" + false) ⇐ true
ie
⇒ Boolean("false") ⇐ true
Yeah. PHP at least ensures that casting back and forth should result in the same thing that you started with, if possible.
-
@anotherusername said in TIL (about the Dark Arts of HTML):
In any case, if you don't know what type of data a variable might hold, empty probably isn't a function you should be using with it.
That bit was just my curiosity. I never really used
empty
much either way. And, as I pointed out above, I did change my condition to explicitly check forfalse
first.Am I not allowed to gripe unless I use the function any more? What has the world come to?!?
-
@Onyx said in TIL (about the Dark Arts of HTML):
So I (kinda stupidly) tried to check if
json_decode
in PHP returned a valid result today. I did this:if(count($json_array)) { ...
Now do note that
json_decode
returnsfalse
on failure so... you'd expect an error if you feedfalse
tocount()
, right?php > var_dump(count(false)); int(1)
Ummm... wait... check the docs...
int count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] )
So, TIL that booleans are countable in PHP. Both
count(true)
andcount(false)
return... 1.Just out of curiosity, I went to check what
empty()
does:php > var_dump(empty(true)); bool(false) php > var_dump(empty(false)); bool(true)
Actually, some testing suggests that it returns NULL on error.
$ php -r "var_dump(json_decode('false'));" bool(false) $ php -r "var_dump(json_decode('true'));" bool(true) $ php -r "var_dump(json_decode('flarble'));" NULL $ php -r "var_dump(count(null));" int(0)
Whether or not
true
,false
, andnull
are valid JSON strings is apparently under dispute.
-
@PleegWat Damn it, you're right, have to fix that...
See, this is what happens when you try to apply consistency to PHP, I automatically buttumed it's
false
because that's what PHP usually does, even for functions that are pretty much the exact copies of C functions on the surface (for examplestrpos
returnsfalse
if it doesn't find a match, instead of-1
which you'd assume if you know any C).To note, I was not actually getting a
false
as input, had another bug in the code that caused it to fail, but I wanted to fix all the checks first and that led me down this rabbit hole.
-
-
@anotherusername See, that's why the iPhone is a way better phone: it's easily discoverable and intuitive !
-
TIL there are a fuckton of Mario games.
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
TIL there are a fuckton of Mario games.
Of course there are. Everytime Mario (or sometimes Luigi?) finds the princess, they and spawn a new Mario (and sometimes Luigi).
-
@Onyx what you discovered is that a function that accepts an array type casts its input to array and
(array) false
returns an array of length 1 whose first entry isfalse
.As annoying as this is, and it is, it's perfectly cromulent.
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
TIL there are a fuckton of Mario games.
That's more than the Sonic franchise:
-
@anonymous234 said in TIL (about the Dark Arts of HTML):
TIL there are a fuckton of Mario games.
That's a really weird list. By what logic is Captain Toad: Treasure Tracker a "Mario game", but not Yoshi's Woolly World?
Also, I played a larger percentage of the games on this list than I like to admit.
-
@asdf said in TIL (about the Dark Arts of HTML):
Captain Toad: Treasure Tracker
The game is a spin-off of the Super Mario series which builds upon a minigame originally featured in Super Mario 3D World.
Completing the game allows players to see the link between Captain Toad: Treasure Tracker and Super Mario 3D World, and having save data from the latter or beating Treasure Tracker allows players to play four 3D World levels as Captain Toad.@asdf said in TIL (about the Dark Arts of HTML):
Yoshi's Woolly World?
The game is the seventh main entry in the Yoshi series of games
The Yoshi games have their own bottom-nav bar.
-
TIL seals are successfully raping penguins for some reason. And then letting them go instead of eating them. WTF?
-
@Yamikuronue said in TIL (about the Dark Arts of HTML):
And then letting them go instead of eating them.
My guess is they don't want to eat their own sperm