« first day (1486 days earlier)      last day (3455 days later) » 

10:00 PM
Anybody running apache 2.4 on windows with opcache 7.0.2-dev by any chance? :P
 
Good luck, mate ^^
 
sorry, I lost you at apache
 
:P
I had a feeling it wasn't going to end well :D
 
then you kept throwing words like "windows"... I closed down my bunker
 
heheheh
 
10:10 PM
$ sapi/cli/php -r 'var_dump(to_int(" 1"));'

Fatal error: Uncaught exception 'CastException' with message 'Could not convert to int' in Command line code:1
Stack trace:
#0 Command line code(1): to_int(' 1')
#1 {main}
  thrown in Command line code on line 1
:D
 
Using that specific of an exception is still a bad idea, imo.
What if we have trouble of converting data from one type to another, but it's not a cast; oh, can't use CastException!
 
@AndreaFaulds hai
you saw my ping?
 
I didn't, actually. But I see you've updated the patch, hmm...
@LeviMorrison Er, and?
Use a different exception?
What's the problem?
 
Your exception is useful for one thing only; that's the problem.
 
Are you going to moan that PDOException exists because things that aren't PDO can't use it?
@LeviMorrison ...and? Having specific exceptions avoids Pokémon Exception Handling. Surely that's a good thing.
 
10:15 PM
1 hour ago, by Florian Margaine
@AndreaFaulds deleted the session commit and fixed the simplexml commit
1 hour ago, by Florian Margaine
you can pull my branch
 
@AndreaFaulds But having too specific of a type makes them resort to that kind of handling.
 
@LeviMorrison Uh, why?
 
you mean that an exception used only at one place is bad?
 
No, seriously, why?
 
10:16 PM
or that an exception defined by php only used at one place is bad, because php, as a language, should provide the minimum number of exceptions?
(I'm genuinely curious)
 
Having a lack of precision means I catch exceptions I don't want to
 
@AndreaFaulds what's Pokémon Exception handling?
 
@bwoebi Pokémon Exception Handling: Gotta catch 'em all!, or, try { foo(); } catch (Exception) {}
 
I really don't have time to discuss this right now, especially because I don't think you are going to listen given that you didn't listen last time.
Nor have you listened to ANY of my advice on this particular RFC.
 
@LeviMorrison You haven't explained your position on the exceptions.
@LeviMorrison I have listened to you. I just disagree.
Listening to your position and accepting your position to be better than all the other positions and adopting it in the RFC aren't the same thing.
 
10:20 PM
@AndreaFaulds Well, that's why we really shouldn't have anything in PHP where the optimal thing to do is very subjective... That's userland.
 
@bwoebi PHP has to be opinionated in places to be actually useful.
 
@AndreaFaulds I really don't think you have listened in this case.
 
@LeviMorrison What makes you think that?
 
Sorry if that's off-base; that's just how it seems.
 
Let me try then @AndreaFaulds - imho it's okay to catch quite generic exceptions at a low level in a library, and convert them into a more specific exception at a location close to where they are called. But having to catch multiple exceptions coming a piece of code is not awesome. And the more exceptions that must be caught are bad, and result in people catching \Exception.
 
10:22 PM
@Danack Er, but don't we have the same issue anyway?
 
@AndreaFaulds true, but then, IMO, we should just fall back to the traditions and not introduce new inconsistencies by mixing the returned things (exceptions, null, false). It's enough to have a mess between null and false. Please don't bring exceptions in…
 
If we throw plain Exceptions, people catch Exceptions
If we throw specific exceptions inheriting from Exception, people catch Exceptions
 
@AndreaFaulds No, let me do a code example...
 
At least in the second case, you have a choice.
 
Things to love about PHP:
- be happy when you guessed the right parameter order at the first try
- when guessing correct return type for failure
- by finally understanding the weird evaluation order of compiled variables vs. expressions
2
 
10:30 PM
@LeviMorrison The problem isn't that I haven't listened. The problem is I've listened to everyone.
 
be happy when you guessed the right parameter order at the first try use an IDE and don't have to worry about that crap.
 
I "listened" to you (i.e. did what you said), and people complained.
I "listened" to other suggestions, and you complained.
I "listened" to other suggestions still, and others still complained.
You can't win.
@Danack IDEs don't really solve the issue
 
@Danack just like when you quickly type strpos($a, $b) so quickly that you miss the hint… and well, $a and $b have same types…
 
@AndreaFaulds Stop doing the conversion for the user and most of those complaints are now invalid.
 
@LeviMorrison "conversion for the user"?
 
10:32 PM
 
Don't convert to an int; just provide an easy way to let the check that something can be converted without dataloss.
 
That's what I see instantly when I type strpos.
 
Yes, I've heard that suggestion before. That doesn't help. It's just as objectionable as every other solution. It's not the panacea you might think it is.
 
> so quickly that you miss the hint
 
Yes, yes, when you program by guessing stuff it goes so much faster.
 
10:33 PM
@AndreaFaulds I think you haven't given that enough consideration.
 
@LeviMorrison No, I have thought about it.
It has all the problems of the other approaches with none of the benefits.
 
The biggest problem I've seen is complaints over how it handles errors; that's true, yes?
 
That's correct.
 
The approach I suggested has only a boolean return type. No errors.
How does that not solve the issue?
 
@AndreaFaulds I think @Levi is being wise…
 
10:36 PM
I'm not so sure he is.
@LeviMorrison Er, you just shifted the location of the error.
It's not really, functionally, any different from the previous proposals, it's just less convenient.
 
Yes, to The Programmer.
 
@AndreaFaulds yes, he shifted it to userland.
 
@bwoebi Which defeats the entire point of the RFC.
 
There actually isn't a completely valid way to determine if something can be safely converted to an int in user-land, at present.
filter_var has its quirks that makes it pointlessly hard.
 
Are you sure? FILTER_VALIDATE_INT seems to work.
 
10:38 PM
@AndreaFaulds IMO, no. the RFC should determine if if can safely converted. if it can, (typecast) $var then is fine if that function returned true.
 
@AndreaFaulds filter_var converts everything to a string first.
It's really horrible, which is why there are so many quirks and edge cases with it.
But generally filter_var has the right idea; it's just really verbose and still has these strange edge conditions.
Err, filter_var has the right idea with the VALIDATE options.
 
Except that it doesn't validate, it converts.
 
@crypticツ replied to your bug :)
 
Which is one more of the problems, yes.
 
@salathe seems that's exactly what I guessed before…
 
10:43 PM
@salathe Should that be documented somewhere? As in on php.net
 
@AndreaFaulds SRP. Either convert or validate, but don't do both.
 
Er, but you can't do only one.
You can do 2, or 1 & 2, but not just 1
Conversion always involves some kind of validation
 
well, the typecasts like we have now are just converting.
they just map the invalid types to e.g. 0
 
Not really. They validate and convert, they just do stupid things if validation fails
Which is bad.
 
just like (string) [] maps to "Array". It's not a validation there.
 
10:47 PM
It is validation of a kind. You have to do these checks
To convert and validate separately is needless duplication of effort
 
@AndreaFaulds Well, then it's a really soft validation, but we're talking about hard validation here.
 
Did you just make those terms up?
 
yes
 
@AndreaFaulds It turned into a novel... gist.github.com/Danack/049ba570e899a1f90468
 
@AndreaFaulds Just imagine in real code:
try {
    $integer = to_int($_GET["str"]);
    // do sth with $integer
} catch (CastException $e) {
    print "Bad idea";
}
if (is_valid_int($_GET["str"])) {
    $integer = (int) $_GET["str"];
    // do sth with $integer
} else {
    print "Bad idea";
}
 
10:52 PM
@Danack Um, I don't see why you can't allow catching both IntOutOfRangeException and NumberException
 
Beacuse no one wants to have to do this:
try {
    foo();
}
catch (CastException $ce) { throw new BusinessLogicException($ce) }
catch (IntegerOutOfRangeException $ioor) {throw new BusinessLogicException($ioor)}
catch (FloatOutOfRangeException $foor ) { throw new BusinessLogicException($foor) }
in their application.
 
But you don't.
 
I let exceptions bubble through my stack to the outside world?
 
try { foo(); } catch (NumberException $ce) { throw new BusinessLogicException($ce); }
 
@AndreaFaulds I here much more prefer the light latter example in favour of the exception-heavy latter example.
 
10:53 PM
@AndreaFaulds I have stuff in mine that is not too dissimilar.
 
@bwoebi Yes, that's one of two use-cases.
Again, what's wrong with subclassing exceptions?
Why must all exceptions only extend Exception?
 
Just don't subclass too far.
 
Why can't you have an exception class hierarchy?
 
You can. Just don't be too specific.
 
@LeviMorrison Why is being specific a problem?
 
10:54 PM
...
 
However, it's generally better to avoid Exceptions altogether, which in context of this discussion means that I don't think Exception subclassing is really what we should be talking about.
 
@AndreaFaulds because it makes you write a lot of boilerplate
 
$ php -r 'try { throw new RuntimeException; } catch (Exception $e) { echo "caught!\n"; }'
caught!
You know that catch works on superclasses, yes?
So I don't see why subclassing 'too far' causes a problem. You don't have to do a catch on the subclass.
 
@AndreaFaulds the other is: $integer = isset($_GET["str"]) && isvalidint($_GET["str"]) ? (int) $_GET["str"] : $default; vs. $integer = isset($_GET["str"]) ? to_int($_GET["str"], $default) : $default;
 
@AndreaFaulds I can't see that in your RFC - what is CastException a subclass of?
 
10:56 PM
@Danack RuntimeException, currently, in the non-committed files on my machine.
 
if IntegerOutOfRangeException and FloatOutOfRangeException are subclasses of NumberException, then yeah, the argument is moot
 
@AndreaFaulds and again, I don't see any big advantage in the latter case.
 
@FlorianMargaine Right, that's what I'm trying to say.
 
@AndreaFaulds are they though? RuntimeException is way too generic
 
@AndreaFaulds Ok, so I was talking about your RFC as you've presented it - I don't work for the NSA, so I can't see what's on your machine.
 
10:57 PM
@FlorianMargaine I know. But @LeviMorrison told me not to use one of the less generic Spl exceptions.
@Danack Yes, I realise that.
 
And I still contend that the function at the end of the gist:
function lowLevelLibraryFunction() {
    if (CastableToInt($x) == false) {
        throw new Bar1SpecificException
    }

    if (inIntNumberRange($y) == false) {
        throw new Bar2SpecificException();
    }

    if (CastableToFloat($z) == false) {
        throw new Bar3SpecificException
    }

    //Numbers are safe.
    bar1($x);
    bar2($y);
    bar3($z)
}
Is still cleaner and easier to read that the equivalent with exceptions.
 
@AndreaFaulds ah
 
@Danack And let's a programmer use whatever error validation scheme they want to use.
That is a big point.
 
^ that's it. @Levi
 
So do other proposals.
 
10:59 PM
@Danack @LeviMorrison dunno though, php programmers are kinda lazy. Doing 90% of the work for them is php motto afaik
 
Ones you argued against.
I don't understand :(
 
@AndreaFaulds Having an Exception by default and an optional parameter that would be returned instead of throwing an exception, you mean?
 
@FlorianMargaine No......and this is deja-vu for a conversation between me and you. It's wrong to try and fix bugs in users code by forcing PHP core to behave in a certain way.
 
@LeviMorrison No, the one before that. Returning FALSE or NULL.
Although that one also allows you to validate yourself.
 
Hi, mysql_error(); not showing in english, any ideas?
 
11:01 PM
I was okay with null but I'd still much prefer a validation function, not a conversion one.
 
There's not really a big difference. A "conversion" function just has different success values.
 
validation > null > false > exceptions … what I currently prefer, ordered @AndreaFaulds
 
I prefer the same order.
 
Hmm, give me a moment. let me list ideas so far.
 
And, to add to the VERY back of the list is a hybrid version that changes what error scheme you use depending on the number of parameters.
 
11:04 PM
@LeviMorrison well, not sure if I should place that before or behind exceptions, but well.
 
@AndreaFaulds If I had more time I'd love to go through and find all those corner cases I mentioned with filter_var and FILTER_VALIDATE_*; I just don't :/
 
setting the language to english, in mysql
 
* to_int($value) // Returns converted value, or FALSE on failure
* to_int($value) // Returns converted value, or NULL on failure
* to_int($value) // Returns converted value, or throws exception
* to_int($value) // Returns TRUE if convertable, or FALSE on failure
* to_int($value[, $default]) // Returns converted value, or $default if it exist
s on failure, or FALSE if no $default exists on failure
* to_int($value[, $except]) // Returns converted value, or throws exception if $
except is TRUE, or some default (FALSE/NULL/etc.) if $except is not TRUE on fail
Er, ignore the name of the fourth one, since to_int is the wrong name in that context
 
you really need a strawpoll.
for internals. What they like. After each proposal has objective evaluation.
issue is objective.
 
@LeviMorrison btw how is return type doing?
 
11:13 PM
I'm stuck.
 
oh damn
didn't nikic give you some suggestions?
@bwoebi any news wrt Derick and phpdbg/xml?
 
OK, hmm, lemme explain the motivations behind the safe casts RFC, so things are clear.
They're of roughly equal weight. Though the first is more important to PHP itself.
 
@FlorianMargaine no, he seems not to be willing to change anything to dbgp and always seems to not understand what I mean when I ask for something not being possible with dbgp.
Given up on that, preparing xml protocol for being RFC'ed
 
The first is to allow you to safely write code in a strictly-typed environment. Currently the main way to convert is explicit casts like (int). This means that the first instinct of many, when faced with a strict int typehint and with string data input, would be to do some_strictly_typed_function((int)$foo); which is bad (if $foo is garbage, it's converted to garbage and accepted by the function as if it were a proper value). By adding to_int which would convert safely...
...you could do some_strictly_typed_function(to_int($foo)); and if $foo was garbage, it'd error instead of being passed to the function
 
we're discussing in circles @Andrea
 
11:19 PM
(When you get time to look at the results, Andrea: 3v4l.org/Y2L95; especially notice the last two lines of output)
 
This goal is accomplished by either returning FALSE (FALSE would fail a strict int typehint), NULL (except for nullable params), or by throwing an exception.
The second is to make form validation and the like easier. I often write stuff like if (!isNaN(parseInt(input.value, 10))) {} in my JS, being able to write the same thing easily in PHP would be great.
 
@AndreaFaulds that's why @Levi and I propose !valid_int($input)
 
@bwoebi k
 
@bwoebi Yes, it doesn't cover the first case well, though. But returning NULL on failure covers both.
 
@AndreaFaulds that's why null is our second preferred solution.
@AndreaFaulds btw. isNaN works in JS because it doesn't differ between floats and integers...
 
11:23 PM
Regardless of what we name it, Andrea, does "1.0" pass the check for conversion to integer?
 
@bwoebi isNaN could be === <any other error value> actually and would work just as well
@LeviMorrison Not for to_int, no.
 
And the rationale is..?
 
@AndreaFaulds yep, null in PHP case.
 
Also, does 1.0 pass the check for conversion to an integer?
 
@LeviMorrison As I just said, no, it doesn't.
 
11:26 PM
1.0 !== "1.0"
 
Oh, uh
 
@LeviMorrison Yes
 
1.0 does, yes.
 
@AndreaFaulds This. I want to be able to call a function with a strict type hint and catch an exception if it fails. Any other way of detecting errors leads to horrible code, in my experience.
 
And the rationale for the difference between those two is..?
 
11:28 PM
@LeviMorrison The floating-point value 1.0 is represented as 1 when converted to a string. .0 isn't generally accepted in integer literals, nor in validators in other languages. Plus it seemed weird to allow, say, ?id=1.0
 
@LeviMorrison And the functions can easily be chained
 
hey room !!!
anyone s awake ?
 
@mlwn Yep.
 
So I have this: $stid = oci_parse($conn, "SELECT * FROM (SELECT fname, lname FROM members WHERE fname LIKE '%$search%' OR lname LIKE '%$search%') WHERE ROWNUM <= 10"); and it doesn't work.
 
@AndreaFaulds ...I didn't quite understand. Based on what you said it sounds like 1.0 shouldn't pass but "1.0" should. Could you restate that?
 
11:30 PM
It basically doesn't execute the LIKE part of the query.
 
Er...
 
2 messages moved from JavaScript : Too Many Cooks
 
It pretty much functions like SELECT fname, lname FROM members
 
The floating-point value 1.0 is represented as "1" when converted to a string. .0 isn't generally accepted in integer literals (1.0 in PHP or any other language is a float, not an int), nor in validators in other languages ("1.0" isn't accepted). Plus it seemed weird to allow, say, ?id=1.0
 
so what the heck
 
11:32 PM
Okay, so I can see why a string would be no, but don't those arguments mostly hold true for float(1.0) as well?
Why are they different?
 
1 and 1.0 seem to be generally accepted as floats. But only the former seems to be generally accepted as an int.
@LeviMorrison The canon representation of float(1.0) is float(1), though.
 
@LeviMorrison what's that, float(1.0)? It's float(1).
 
I'm just not getting it, it seems.
^^
 
@LeviMorrison I'd considered accepting non-integral floats too, but then "1.234" would be a valid int string, and that just didn't seem right at all
@LeviMorrison Also, this restriction means that any string satisfying this expression will be accepted: (string)(int)$string === $string
@LeviMorrison Also FWIW Python's int() doesn't accept '1.0' but does accept 1.0 ^^
 
Well, I'll just let that one sit on the shelf for a bit ^^
 
11:42 PM
Yeah, there are arguments for both sides. I really like that (string)(int)$string === $string thing though :p
All I need now is to find out what @NikiC thinks of just returning NULL
 
I need to work on designing how covariance checks are done; I just can't find the motivation.
I don't like any of the solutions I've tried. I've thought of changing the parser to be three passes but I'm not 100% certain that would fix my issue anyway.
 
@LeviMorrison The problem is autoloading
You'll not necessarily have a complete graph until call-time, unless you pre-load
But that means you have to figure out when to re-run the checks
 
Actually, autoloading isn't the problem. If people do one class per file and do autoloading it works ^^
The problem is when people do same-file stuff.
 
@AndreaFaulds Ah, I see that your "executive decision" has been overthrown again? :P
 
@NikiC Last time it was NULL, this time it was optional default else exception...
 
11:45 PM
I need to delay the binding until all of the classes from the same file are loaded, and then trigger the autoloader if necessary.
But... that still doesn't necessarily cover all cases.
 
@NikiC How do you feel about just returning NULL?
 
@AndreaFaulds I'm okay with it.
 
Hmm.
See, I'd previously had it return NULL, then made it return FALSE.
But, after thinking about it, FALSE is dumb.
 
No, it's not.
It's just irrelevant.
Do whatever is most likely to achieve a majority. I believe that the exact choice is rather inconsequential.
 
Actually, yes. I don't really think FALSE is bad. But people seem to like NULL more. And it's nicer in some ways (?int vs mixed).
 
11:54 PM
Yes. It's not that false would be bad per se, but null just has advantages over false (like coalesce operator, eventually nullables etc.)
also, by the very definition of null being not-a-real-value I prefer null.
 
I disagree over NULL's meaning, but I agree it's more appropriate.
 
@AndreaFaulds so, what's null then? It's the userland equivalent of IS_UNDEF.
 
NULL is the explicit lack of a value. It're pretty annoying that PHP doesn't have a distinction between that and the implicit lack of a value.
 
it's a shame that php doesn't have undefined like js...
 
@FlorianMargaine this, although void, but yes
 
11:58 PM
@DaveRandom Yeah, JS has undefined for implict lack, something PHP ought to have but sadly lacks
 
guys guys girls
is it something everybody agrees on? :P
 
It's just a hunch, but I bet isset() thinks NULL means unset because originally, accessing undefined variables wasn't an error, they were just NULL
But that's just a hunch.
 
JS reunites all of you!
 

« first day (1486 days earlier)      last day (3455 days later) »