r/lolphp • • Nov 15 '14

new safe casting function RFC. casting "-10" to string is valid but casting "+10" is not..

here the comment where one user asked the author of RFC about this. I am not able to follow his reasoning. What do you think?

22 Upvotes

67 comments sorted by

View all comments

-1

u/[deleted] Nov 15 '14 edited Nov 15 '14
  1. I'm not male.
  2. It's a tradeoff. Accepting the narrowest possible range of input means you have a much simpler rule (zero round-trip data loss), and applications can always add support for white space or plus signs or whatever themselves. On the other hand, allowing things like white space and positive signs might make it more useful for some applications. I suppose it depends whether you think losing white space and explicit signs matters.
  3. It's not a string parsing function, it's a lossless-only cast function. That's quite an important distinction. It doesn't, and probably shouldn't support things like hexadecimal and octal, whitespace, positive signs or trailing characters.
  4. This is an RFC. Anyone with wiki privileges can make an RFC. It's not really fair to complain about proposals that haven't been adopted, are currently under discussion and haven't even been voted on.

28

u/[deleted] Nov 15 '14

It's not really fair to complain about proposals

Isn't that like the whole point of RFCs (Request for Comment)?

0

u/[deleted] Nov 15 '14

I should've suffixed "in /r/lolphp". RFCs are of course to allow scrutiny of proposals before adoption. But to post it to /r/lolphp so it is mocked and the thread in /r/PHP is vote-brigaded, would hardly seem appropriate.

5

u/i_make_snow_flakes Nov 15 '14

It is sad that you see it that way. To mock you was never my intention. And if you have seen me in /r/php, you ll know that I don't give..well, that I don't care much about votes, up or down, particularly in /r/php.

-6

u/[deleted] Nov 15 '14

To mock you was never my intention.

You posted it in /r/lolphp.

And if you have seen me in /r/php, you ll know that I don't give..well, that I don't care much about votes, up or down, particularly in /r/php.

It was still vote brigaded.

→ More replies (1)

11

u/i_make_snow_flakes Nov 15 '14

I'm not male...

Ok.

It's a tradeoff.

So you are trading sane behavior for simple internal implementation? I am not getting your point...

Accepting the narrowest possible range of input means you have a much simpler rule

+10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it?

I was mostly baffled by your this argument . Do you still maintain it? Or do you think it was flawed?

-7

u/[deleted] Nov 15 '14

So you are trading sane behavior for simple internal implementation?

No, implementation-wise it's the same.

+10 is not acceptable for an Integer? Why? If you have an input box to enter an integer, will you be able to tell a client, with a straight face, that he cannot enter +10 into it.

In that case, you'd probably want what ext/filter provides if you're taking form input. This isn't really suited for that use case.

I was mostly baffled by your this argument . Do you still maintain it? Or do you think it was flawed?

It's not an argument for this behaviour. It is the principle which leads to this behaviour.

0

u/[deleted] Nov 15 '14

[deleted] — view deleted comment

-6

u/[deleted] Nov 15 '14

It's a useless and stupid principle. If you want to know why, read up on signs of integers.

No, I understand signs of integers. But this isn't really intended for cases where you want whitespace and positive signs.

Why should /index.php?user_id= +10 be accepted?

5

u/Innominate8 Nov 15 '14

Who is arguing for whitespace? This is about signs.

3

u/[deleted] Nov 16 '14

I think the argument is about the plus sign standing for white space in URLs?

8

u/i_make_snow_flakes Nov 15 '14

This isn't really suited for that use case.

Well, what is the intended use case then..Can you give some examples?

→ More replies (26)

5

u/[deleted] Nov 15 '14

Accepting the narrowest possible range of input means you have a much simpler rule (zero round-trip data loss), and applications can always add support for white space or plus signs or whatever themselves.

All that would be a good argument, if you were not supporting negative signs while ignoring positive signs. As it stands, you're supporting casting -10 but not +10. that's what makes it an lol, like the rest of PHP.

-4

u/[deleted] Nov 15 '14

All that would be a good argument, if you were not supporting negative signs while ignoring positive signs. As it stands, you're supporting casting -10 but not +10.

Huh, how so? That would mean you couldn't represent negative numbers.

There's no need for supporting positive signs, given numbers are implicitly positive without them.

5

u/[deleted] Nov 15 '14

numbers that start with + are also implicitly positive, but you don't support them. its inconsistent behavior to support - but not +. Mathematically, +xxx is as valid as xxx or -xxx.

-2

u/[deleted] Nov 15 '14

numbers that start with + are also implicitly positive, but you don't support them.

Er, no. That's making a number explicitly positive. Without the + it's implicitly positive.

its inconsistent behavior to support - but not +.

It's not if you think about it. + is redundant since a number without it is positive anyway. - isn't.

8

u/[deleted] Nov 15 '14

That's making a number explicitly positive.

So you agree that its explicitly a positive number, but you'll treat it as a string. Smart.

+ is redundant

Loosely typed languages are all about supporting redundencies though. PHP supports all kinds of crap, e.g 0 == false. The fact that you're not treating +100 as being a number is not only mathematically incorrect, it also breaks PHP's own shitty conventions, as well as the principle of least surprise.

-2

u/[deleted] Nov 15 '14

it also breaks PHP's own shitty conventions

Well, yes, that is rather the entire point of these functions.

→ More replies (3)

0

u/[deleted] Nov 17 '14

[deleted] — view deleted comment

0

u/[deleted] Nov 17 '14

Because "he" was used in the OP.

0

u/[deleted] Nov 17 '14

[deleted] — view deleted comment

3

u/[deleted] Nov 17 '14

The author of that RFC isn't male. The author of that RFC is also me.

Also, English doesn't have grammatical gender. If I say "the author", I am referring to a human being, so the pronoun used is based on the gender of that person, so "he", "she" or "they". For other nouns that don't refer to animate beings, "it" (singular) or "they" (plural) is used.