« first day (1465 days earlier)      last day (3488 days later) » 

10:00 PM
An error can be a value.
 
@AndreaFaulds Yes, there is.
 
You only used exceptions in exceptional circumstances
 
An error is an exceptional circumstance: in this case it indicates a value that should not have been passed to to_int in first place
 
FWIW, in every case where I used something other than exceptions for errors, I was sorry later.
 
No, not really.
If something is expected to fail, an Exception should not be used
 
10:01 PM
No, it is actually an Exception that I expect, so I can handle it
and the exception type should also be documented so that I can catch precisely that exceptional case
 
You can handle a return value.
 
I still think that exceptions would be best for the 5 reasons I listed.
 
no, I can't handle a return value if I have to basically rewrite a closure with a check against false for every array_map I do :P
 
Also... we don't throw exceptions in core function.
 
array_map('my_own_to_int_that_throws_if_false', $values);
@AndreaFaulds does that mean that you use bad-practice-as-a-convention? :|
I don't buy that
 
10:03 PM
It's not bad practice
 
@AndreaFaulds Why not? Bundled extensions such as PDO/MySQLi do.
 
Again, Exceptions are for the exceptional
 
it is
 
@Ocramius That deserves caps.
 
and passing an resource to to_int is an exceptional case
 
10:04 PM
EXCEPTIONS ARE FOR THE EXCEPTIONAL
 
and as I said, it is an exceptional case
 
Calm down, @Andrea.
 
Nope.
 
:P
 
Let me make an analogy with "baking metamphetamine": would you pour Chloridric acid or Caustic Soda in first?
depending on what you do, one of the two is going to blow your place into flames.
 
10:05 PM
Look, no need to get all heated. Remember, if you do it my way you don't have to choose between false and exceptions.
All this fighting is a case for doing it my way.
 
@AndreaFaulds Wouldn't it be exceptional if to_string is called on an object not implementing __toString()?
 
an invalid input value causes failures
 
No, your way doesn't avoid the choice, Levi
Now I have to do two function calls.
I might as well just use (int).
 
@AndreaFaulds Yes, it does.
And no, it's not two calls.
And if everyone else will calm down for a second, let me also explain something I feel is really important.
 
@LeviMorrison Okay, calm now. Go ahead. :)
 
10:07 PM
The paradigm of 'do something, then check for an error' is not as good as 'check to see if something can be done, and if it can then do it'.
if (to_int($var) !== false)
if (can_be_safely_cast_to_int($var))
 
Sure, but to_int isn't for that use case primarily
 
Sure, the latter requires the caller to use (int) $var afterward.
It's not as convenient.
 
It's to make writing relatively safe PHP code easier.
The point is to be as convenient as to_int()
What you propose is no more convenient than filter_var
 
I will vote no on this.
 
Thus, it is useless.
 
10:09 PM
And I will encourage everyone I can to vote no on this.
 
@NikiC What do you think?
 
You won't listen to reason any time I talk about why int|false is bad.
 
can you clarify a bit on the use-case? What happens if a false slips through into my core domain?
 
At the absolute minimum you should do ?int
 
(because I didn't check it)
 
10:10 PM
@Ocramius The main point was twofold.
 
@Ocramius Never pour water in acid :P
 
@webarto also true :P
 
1. Simple validation: if ($x = to_int($_GET['x']) !== FALSE), 2. Discouraging dangerous behaviour with strict type hints: foobar((int)$_GET['x']) is BAD BAD BAD - foobar(to_int($_GET['x'])) is almost as short, yet it's much safer
 
@Ocramius No one shot himself accidentally from a loaded gun. Also true :P
 
@AndreaFaulds I don't think foobar(to_int($_GET['x'])) is any better if you return |false.
 
10:13 PM
It's intended to be similar to JavaScript's parseInt, but more restrictive. That was my inspiration. I use parseInt frequently in the programming work I'm actually paid to do.
 
foobar(to_int($_GET['x'])) applied to a definition foobar(int $var) (int only in docblock) will be as troublesome, as it forces me to wrap all to_int() calls in an assertive method
 
Hey @webarto, bored?
 
@Ocramius How?
 
@DaveRandom Of life? Not quite yet.
:P What's up?
 
function safe_to_int($int)
{
$cast = to_int($int);

assert('integer', $cast);

return $cast;
}
 
10:14 PM
And I know I've brought this up before, but the manual entry of null describes why it would be the correct type:
> The special NULL value represents a variable with no value.
 
@Ocramius No need:
 
where safe_to_int() halts execution before it goes somewhere else
 
If you can't return an int, then you should return nothing, or null.
 
that's the entire point of it: avoiding continuing computation if it's not an expected value
 
@AndreaFaulds If to_int returns false, though, then a fatal error will occur and devs will just change it to foobar((int) $var) to "fix the bug." If it throws an exception then a proper error message will be displayed showing what went wrong.
 
10:15 PM
@webarto I need some extremely simple styling done, I suck at CSS and hate it and you don't and I wondered if you would be so kind as do donate 10 minutes of your time to it? Like I literally have 2 comically simple HTML pages
 
some_value(to_int(" BAD")) ==> Recoverable Fatal Error: integer expected for param $foo of some_value, boolean given
@TheodoreBrown Why would it be fatal? It's only as fatal as an exception.
 
@DaveRandom Yeah, sure, if I'm up to the task.
 
@rdlowrey apparently your socks also require php5.5 - is that an actual requirement or another 'people should be using 5.5.'? As Artax depends on nbsock, even though it's requirement has been put back to 5.4, it can't be installed on 5.4.
 
@AndreaFaulds Assuming the dev has an exception handler which displays an error then it won't be fatal.
 
@AndreaFaulds yes, and your current API causes a bad crash there
 
10:16 PM
@AndreaFaulds You'd get the same with null, unless you use ?int but I'd argue that is exactly the intended behavior!
 
@Ocramius Bad crash? How
 
@TheodoreBrown "devs will just change it to foobar((int) $var) to "fix the bug."" You're trying to work around developers being stupid at the language....that's not a good idea.
 
@LeviMorrison A BAD VALUE != NO VALUE
 
@AndreaFaulds recoverable fatal?
 
If I pass garbage, I expect garbage. Not the valid value NULL
 
10:16 PM
@AndreaFaulds to_int("not an int") is not a bad value.
 
I don't want to clone MySQL.
 
It's just not an int.
 
Sure. It's also not a lack of value
 
If I pass garbage, I expect an exception and being able to throw an exception (with the data chunk) to be logged somewhere
 
We can't have NaN in PHP?
 
10:17 PM
@AndreaFaulds It's the lack of an int.
 
Not at all.
That's not the point...
 
Yes, it is.
 
@LeviMorrison Excuse me, you did not write this specification or this function
 
Anyway, I'm done.
 
I know what the point of the function is
 
10:17 PM
That would solve the debate...
 
@AndreaFaulds I have spent way more time thinking about PHP type theory and practice than you, of that I am absolutely certain.
 
@webarto 1 2, feel free to adjust the markup however you want as long as all the fields are there
I will owe you several beers
 
And that is exactly why I can say what I say, despite not being the author.
 
@LeviMorrison I don't care about type theory
I care about getting shit done
 
And this is why you are wrong.
You should care about type theory AND practice.
 
10:19 PM
PHP isn't about purity. It's about practicality.
If it's pure but impractical, why bother?
 
@DaveRandom Beers! Can you give example of how you want it too look?
 
eh... it got into bullshit talk now. I feel like it's laravel 4.0 all again.
 
@Ocramius LOL
 
Anyway, as stated before, I will vote no and encourage everyone to vote no on this RFC if you return int|false.
 
10:20 PM
And that's the end of it for me.
But, more importantly, I was trying to help you.
 
@DaveRandom ajaxrequestor is defined?
 
You just refuse to see that, and that's okay. You don't have to take my help.
 
@webarto "Not shit" i.e. not the browser default stylesheets, aside from that I have no idea, I don't do front end. Light colours and rounded edges, I guess
 
Maybe there's a reason the HHVM people would rather have ?int (and a hint: it's not JIT)
 
No, I understand you're trying to help
I just disagree with you.
 
10:22 PM
Disagreeing here means you don't understand really important things.
 
No, it doesn't
I do understand these things
 
And given that you have been the one pushing for better types in PHP that is very, very alarming.
 
@FlorianMargaine Oh yeh everything works mechanically, I just cannot do styling (well I can, but @webarto can do in 10 mins what would take me several hours, and has good ideas about how stuff should look and that kind of thing)
 
The point is you are arguing from a perspective of type purity
 
No, I am not.
 
10:22 PM
I'm arguing from a perspective of practicality
I realise it's impure, god forbid.
 
I'm speaking about practical lessons learned from theory.
 
I make stuff do stuff, I don't make stuff look nice
 
I know, that's bad.
 
@AndreaFaulds why is (from your PoV) null less acceptable than false?
 
@DaveRandom CSS is the crappiest thing ever.
 
10:23 PM
just for consistency with the old (broken) API?
 
And for reference, your function is 'pure' in that it has no side effects.
 
@DaveRandom oh yeah I forgot something, it should work, my bad
 
So I don't know why you keep saying it's not pure.
 
@Ocramius Not really. It's mostly because that'd be accepted for a nullable typehint
Which is far from ideal
 
No, that's exactly ideal.
 
10:24 PM
@AndreaFaulds given that I don't want a fatal error from to_int() return types passed to something else (in first place) I don't see how false is better
 
Actually, no, Levi. Here's something I know you perhaps don't: It's unfortunately taken too long for DB vendors to realise that no value and an invalid value are not the same.
 
@DaveRandom ftr if it wasn't in a handler, ajaxrequestor wouldn't be defined at this point so it wouldn't work. But since it's called way after it's loaded it's fine
 
@Ocramius You don't get a fatal error, you get a recoverable. And I'm hoping, with Nikita's RFC, that you'll get an exception.
 
@AndreaFaulds Allowing null in databases is generally a mistake.
 
@webarto Yes, yes it is.
 
10:25 PM
if you allow a column to be null then you are ASKING for that behavior.
If you don't want bad or no value, then don't use null.
 
No, not at all
 
It makes no sense, you threw in some weird shit and you get amazing things.
 
Hoisting doesn't work across different script tags
 
"ALLOW NULL" != "DISCARD GARBAGE AND PRETEND I PASSED NOTHING"
 
But yo udidn't pass garbage.
 
10:26 PM
@FlorianMargaine Yeh, you'd have to be pretty damn quick to hit that submit button before the external resource had loaded :-P
 
I want robust software. Software which errors on bad input instead of pretending there was no input.
 
to_int() never returns garbage.
It returns int or null.
 
Er, no, it returns int or false.
 
@AndreaFaulds a recoverable error is only catchable via an error handler: I want try-catch to handle that. Yes, this would be more acceptable with @NikiC's suggested change in fatals, but it's still a function passing garbage around if it fails to cast.
 
FALSE is a garbage value, it's not an integer
 
10:26 PM
(garbage both in the null and in the bool case)
 
It's GIGO... but you can detect the GO easily by looking for FALSE.
 
you detect the issue easily also with null
 
Okay, look.
I am completely serious: go write a bunch of Hack code.
Use ?int
use nullable types and don't use them where appropriate.
 
@webarto There's a guy at work who does all kinds of craxy shit with CSS animations and stuff, I really don't know how you can do that kind of stuff without killing yourself
 
Then come back and talk to me. I don't think you are speaking from experience with ?int
For someone speaking about practicality I think you are out of experience domain with it.
Talk to people with LARGE codebases that use it too.
 
10:29 PM
Eh, that might be true. I don't use Hack. I write small programs and try to make them robust enough.
 
Also @FlorianMargaine I'm aware of the issue with ordering and I will sort it out, the templating logic is screwy atm because I'm in "just get it out the door" mode
 
Right now I'm pretty sure you are designing to_int for exactly one use-case: yours.
 
I don't want nullable types to break my apps.
 
@DaveRandom That. My buddy does frontend, we get about same salary, but he's on medications and drinks to forget, every day.
 
@LeviMorrison Not at all.
The returning FALSE isn't for me, it's to discourage people from doing the really lazy and dangerous thing.
 
10:29 PM
Which is not something you should design around; people have already said that.
 
Well, returning FALSE for use case (1) is for me.
They're wrong.
 
People will always be lazy and dangerous
 
Sure.
 
fwiw, as said before, I don't want false to break my apps either :)
 
If the language makes doing the sane thing too difficult, it's bad.
 
10:30 PM
Additionally, we don't actually have scalar types right now.
 
@Ocramius Don't use to_int() then.
 
Which means to_int() isn't any safer if you don't check its return value.
 
@AndreaFaulds if this RFC is accepted, I won't use it
 
So you need to write:
 
I'd rather have a userland impl that fails with a specific domain (type conversion) exception here
 
10:31 PM
Yes, but nobody needs to force cast now
 
Uhm...
I think you are wrong.
Go check on github and verify that you are wrong about that.
 
Well, sure, you do need to force cast in some places
However, to_int() is still useful without strict types for another use case, one I'm intimately familiar with...
 
Tons of code out there uses to_int in it as well.
That's another reason I don't like it.
Just upgrading means I have to rename mine. And you can say "should have namespaced", but this code is pre-PHP 5 so..
This will cause conflicts, and not because I was doing something stupid.
 
@AndreaFaulds The only thing I'm strongly against is Levi's suggestion. The other three options are all okay with me.
 
Hey anyone have experience using php mail() ?
 
10:34 PM
Living in Salford at this time of year sounds like living in war zone, shit keeps exploding, there's a bunch of kids running around with display fireworks :-/
 
Any reason why my php mail() code 'sometimes' results in false?
 
@redshift failed to use sendmail?
 
@redshift You need to talk to your sysadmins and get them to provide you with an SMTP relay, what you are doing is non-trivial even for email
And email is stupidly complicated to begin with
 
user895378
@Danack Grr, sorry, didn't realize that one was set to 5.5 as well. Will fix and force push another tag.
 
Hey, it's "Simple" mail transfer protocol
 
10:35 PM
I think I'll just put the RFC to internals.
I know Levi doesn't like it. I'll have to live with that.
 
There will be an internal SMTP server for what you are doing
 
Also, a look on github suggests that some of the to_int functions out there could be replaced by just using intval()
 
@AndreaFaulds I think it might be safest to just have a second vote for the failure case. Unless internals provides us with some amazing insight as to which is the best option ^^
 
@Ocramius Much like "Simple" object access protocol
 
@DaveRandom thanks for your feedback. I'm an extreme newbie...only know basic php...but work in an office with a very severe restrictions in server access...what kind of server access do i need in order to setup SMTP for a simple contact form on a website I developed?
 
10:37 PM
Optimism - nikic has it.
 
@AndreaFaulds Lots of people in this room don't like it either.
Let's not pretend like I'm batcrazy.
 
@NikiC Two-way vote, three-way vote, or two votes? (false/exception, false/null/exception, or return/exception and false/null)
@LeviMorrison I realise you're not the only one
I also don't think you're crazy
 
And really, don't do exceptions.
 
I simply disagree with you
 
@AndreaFaulds 1. vote for adding the functions. 2. vote three way between false/null/exception.
 
10:38 PM
Failing the cast is not exceptional, not as you've designed it.
 
@redshift You need to talk to your sysadmins and explain what you are trying to do, no-one else can help you until you can tell us more about your email set up, I'm afraid
There are a million and one ways that it might be set up
 
@DaveRandom sigh, ok
 
@NikiC OK.
 
@LeviMorrison What don't they like? From what I heard everyone has their own preference as to which approach is right and there is no strong consensus in any direction.
 
Which makes my suggestion very attractive: avoid error conditions.
No idea why you are so strongly opposed to that.
Let everyone do it their way by avoiding the issue altogether.
 
10:43 PM
@redshift Sorry I can't be more helpful, but there are just too many variables to suggest anything that has any vague hope of working. Essentially what you need to know is how an arbitrary email client can send email within the network. Ideally what you need is an SMTP server address, port, username and password, that is probably going to be the most robust solution.
 
@AndreaFaulds Also, please ask for 2/3
 
@AndreaFaulds yeah - would also be good to list the advantages / disadvantages of the individual options.
 
@DaveRandom that IS helpful. Thanks. So, basically by doing the SMTP method...the form script (lets say phpmailer) is using my email account to send the mail? don't quite understand why the script needs smtp username and password..what is that for?
 
@LeviMorrison Why? It doesn't touch the language.
 
10:45 PM
If Internals can't agree to the tune of 2/3 then it shouldn't pass.
 
@NikiC I'm not really sure I could do that well... the rationale has been somewhat expanded, though: wiki.php.net/rfc/safe_cast#rationale
 
I understand we ALLOW less than that, but it's been a pain point of many RFCs.
People try to justify that it is 50% needed because they want it to pass.
 
A 2/3 vote doesn't ensure much
Integer Semantics passed despite being highly contentious
 
It ensures that more people agree than 50%
 
@AndreaFaulds @NikiC @LeviMorrison for the record, I personally think that all of these changes, anything with an error handling question mark, needs to be put on hold until the more general "exceptions in the engine" question is decisively answered. IMHO the only actually sensible answer to error handling here is exceptions (as in a lot of cases, such as scalar types and the new "catchable fatals" that have appeared), need to stop dealing with it on a case-by-case basis.
 
10:48 PM
@DaveRandom It's somewhat orthogonal as this is a standard library question
 
Also, determining if an 'error' is exceptional or not probably still has to be done case-by-case anyway.
For instance, in Python you end iterators by throwing a particular exception.
 
@redshift The username/password may or may not be required, but they probably will be. It's how the server determines that you are allowed to send mail... it can be set up in other ways, but username/password is the most common and in many ways the simplest.
 
It has since been considered to be a bad decision.
 
@LeviMorrison This is true, but right now you aren't really even allowed to do it (in so far as there are rules)
@LeviMorrison That sounds terrible
 
But it stemmed from this type of discussion.
 
10:51 PM
@DaveRandom would using phpmailer be a good step in the right direction ?
 
"What if None is an acceptable return value for this iterator?"
And so on.
 
@LeviMorrison That sounds like a very valid argument ^^
 
Anyway, I'm going to put the RFC to internals. I'm happy enough with it.
BUT
 
@NikiC Yeah, but throwing the exception to end the iterator they decided in retrospect was a bad idea, but too late ^^
 
@redshift Yes, but only if you have the details to tell it how to send the mail... also for the record I much prefer swiftmailer, but it's up to you, both libs are largely capable of the same functionality
 
10:52 PM
I might delay the vote until after Exceptions in the Engine, if I think it's worth it.
That sound alright?
 
@LeviMorrison it's a bad idea, yes. the question is whether the alternatives are worse ;)
 
@DaveRandom which of the two is easier for a newbie to use? Will my server admin give me the values I need for the SMTP info or is that typically not given to people due to spam abuse?
 
@NikiC Whenever you can push the error handling, including how errors are determined, to the user you probably should.
 
The only real ways to solve it is a) generics, i.e. returning an Option<T> from next() or b) having a separate valid() method, like in PHP. I don't think there are other options, apart from throwing an exception.
 
Returning a tuple would also work in this particular case.
(That's what EC 6 does, btw)
 
10:54 PM
@LeviMorrison and that, right
 
Hmm, you know returning an Option would work for to_int :p
 
though I don't think a tuple is particularly nice either...
 
Though people confuse Optionals and Nullable types :<
 
so, guys and gals, let me draw this discussion to a satisfying conclusion:
PROGRAMMING SUCKS!!!
4
 
10:56 PM
to_int() could return a tuple. I suggested this but it was unpopular. I am also not sure that this is the best option, but I think it's better than int|false, at least.
 
user895378
I need tuples.
 
user895378
Pleeeeeeeeeease.
 
@redshift Entirely unknown. But at the end of the day, the company has given you something to do and they need to either give you a mechanism to do it or concede that it cannot be done... that element at least is pretty black and white. For the moment, take the question "how do I send internal email with PHP" and drop the "with PHP" part of it - find out how to send internal email with e.g. Thunderbird.
Once you can do that, you're most of the way there because you just need to plug the right values into your code.
 
@rdlowrey I think you need a different language.
 
user895378
I think we all probably need that.
 
10:57 PM
btw don't use Thunderbird in general, it sucks, but precisely because it sucks it's a good thing to use for this exercise because it's a lowest common denominator of features
 
How much of the stuff that you write does the language help you with?
 
@DaveRandom which mail client do you use?
 
@DaveRandom thanks, i'll try....
 
Basically none. It just so happens that when you use the tools you write it would be nice to use PHP. The tools themselves... not so much.
 
All my email, including work, is now handled by gmail
 
10:58 PM
Ok
 
But I actually quite like (please don't shoot me) Outlook
 
@AndreaFaulds the "open questions" section looks stale
 
tbh they all suck, but for connectivity options and settings granularity Outlook is good
 
Alright, heading home. Catch you guys later.
 
Well, I've gone and done it now! news.php.net/php.internals/78160
@NikiC Haha, I'll fix that. - done!
 

« first day (1465 days earlier)      last day (3488 days later) »