« first day (1726 days earlier)      last day (3226 days later) » 

5:00 PM
okay, well, that's how an argument should progress, right ^^
 
You just never ran into the scenario where what you were sorting was an array of floats, where two floats being compared happened to be both positive but less than 1.0.
using return $a - $b is exactly where you're going to get bitten here. I'm simply trying to explain that to you and why it's not good idea to do so.
 
I'm sad to announce that at the end of the month I'll be leaving Google... It's been an awesome time...
 
@Sherif I've always been writing financial or gambling apps and I always knew exact precision I had to work, so yes, $a - $b worked fine for me and never had or could possibly have bug related to that. Basically, if you know what you're doing it's fine.
 
@ircmaxell oh, why?
Where are you heading to now?
 
@Leri I love how you're still completely missing the point :)
 
5:03 PM
@Sherif For which I hope I honour enough your care-taking: Thanks a lot for that.
But I'm fine about that.
(and your example was integers)
 
Sure, be fine with it. Just don't start handing out poor advice to other people.
@hakre That's why it's called an example. It doesn't represent every possible permutation of values you can run into there. It just represents a working set.
Wow you're dense.
 
The only thing that would bother me with the answer is the fact that usorts first parameter is taken by reference and the example can't be just copied and run
 
@ircmaxell sigh… yeah it works, but that's already all what's good about that code.
 
@Sherif you might also want to add that answer to the links to the other comparison operators in the question
 
@Rangad I did.
There's only one page in the manual for comparison operators and it's linked.
 
5:14 PM
@Sherif oh, yeah, just tried the spaceship operator with unicode strings and it didn't work o_O.
 
No, I mean the question on so. Most operators are referenced in the question with links to other questions/answers dealing with them.
 
It compares strings as byte arrays. So it's equivalent to strcmp. The same behavior you'd get from "foo" > "bar", for example.
@Rangad Oh, didn't search for a question about the spaceship operator, but it looks like there's only one question there and it has been down voted to a -6 :/
Don't feel too happy about linking to that.
@Rangad Also, fixed :)
 
Hi, does anyone know why my symfony command has different result if it's run from controller or from CLI? What's the catch? tnx ;)
 
Hmmm, maybe if I link to it people will upvote it again?
heh
 
@What Well this has perhaps to do with the environment that command is executed in. Don't you think so?
 
5:26 PM
Now the question is do I link to the answer there in the question I'm linking to? Or do I simply resubmit the answer?
 
Well, simply revert stackoverflow.com/revisions/3737139/83 if you wish to handle it differently
 
meh
 
5:44 PM
=] burgers!
yay \o/
 
@Sherif LOL. I am not saying that spaceship operator is not good (besides its name). It's good because you don't need to worry that you need to implements via strcmp, take care of precision, etc. I am just saying that in most of implementations there's $a - $b, simply because that's all is needed for the task.
 
@ircmaxell by your own choice? Or some NDA'ed reasons?
 
By my own choice
 
@Leri Most is a bit dubious there since I've already demonstrated how it doesn't work for a broad majority of cases, such as when the values are negative, causing subtraction to flip the signs and give the wrong result for the comparison, e.g. $a = -2; $b = -3 resulting in -2 - -3 == 1, which tells you that $a > $b and that's inextricably wrong. So in fact, return $a - $b actually only works under the specific conditions that $a and $b are always positive integers.
 
@ircmaxell good luck to you
I'm currently looking for dev work. Might go back to being a sysadmin :/
 
6:04 PM
@taco where are you based?
 
Atlanta
 
@Sherif You totally miss my point.
 
posted on July 08, 2015 by nlecointre

/* by OcuS */

 
bleah, clearly I can't do math today
@Leri Did I? What was your point?
 
@ircmaxell I've been a dev for 3 years, but all over IT before that. linkedin.com/in/luis1
Was hoping to stick with Dev, but I'm not senior level for Angular and nobody wants PHP it seems. It's all full stack, front end, back end in something else
Anybody using Docker? I'm looking into Weave for networking
 
6:07 PM
wow, I'm still getting linkedin spam from recruiters
 
@taco if you want to move to NYC, let me know
 
I do. But wife won't move right now
Planning on our first kid right now, family is here :)
 
@hakre I don't know... the command is executed on the same environment with CLI and from controller.
 
@Sherif It was that when you need to sort array you already know all the specifications about array items, therefore you can implement sorting function for a specific items. And for me and for majority $a - $b was all that was needed.
 
@Leri oh I didn't miss the point that it works for the majority of your use cases. I just doubt that you can say it works for the majority every one's use case, otherwise we'd just use sort and there'd be no need for usort, right?
 
6:20 PM
@What so the CLI creates a controller to invoke the command?
@Sherif I don't think you say that any operator will work for all use-cases, won't you?
 
@Sherif This conversation is getting nowhere. I see no point in continuing one.
 
@hakre No, it's not about the operator. It's about the expectation from what the callback returns.
 
Both points are correct and we're repeating the same over and over again.
 
@Sherif you're really fixed.
Anyway, great news: Food was great!
So my decision to not discuss too much here and do some cooking instead was right.
 
usort is expecting you to return an integer of -1, 0, or 1. If you're doing something like return $a - $b from your callback and $a happens to be a value of 2.5 and $b happens to be a value of 2 you get 0.5, which gets cast as an integer to 0, indicating that the two values are equal, which isn't true.
 
6:24 PM
Greetings Guys
 
So by doing that you aren't adhering to the contract that usort expects. That's all.
 
@Sherif I know times of the manual that were documenting the return value being less, equal or greater zero. so that was the contract and I wonder why it's now changed.
 
@hakre It's never changed.
 
well then it's fine, please don't postulate a different contract then.
 
@Sherif Not really:
> The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
 
6:26 PM
Hmm? How have I postulated a different contract?
@Leri Yes, what did I say that was any different than that?
-1 is less than 0. 1 is greater than 0 and 0 is equal to 0.
The keyword there being integer.
0.5 is not an integer.
 
in PHP 0.5 can be an integer.
 
No it can't.
You can cast 0.5 to an integer, which is what usort will do there, but then you have 0, which is wrong.
Hence why you shouldn't rely on that. Instead, adhere to the prototype which defines a return type of integer.
 
6:42 PM
it's not wrong. if the 0.5 is returned with the intention that it is represented as integer 0 this is all fine that 0.5 is 0. it's not wrong at all. it's just what happens it's not wrong nor right.
you don't program a computer for wrongness or rightness.
 
Anonymous
@Rafee o/
 
@hakre Actually, it is, and you do. The function is meant to sort and if your callback registers that a value of 2.5 is equal to a value of 2.0, you haven't really sorted. Computers are binary. They don't do well with gray areas. All they know is boolean logic. Things are either true or they're false. So by definition, you do program a computer for wrong or right.
 
wrong and right is not the same as true and false.
 
Isn't it?
 
no it's not. And I wonder a bit if I really need to explain that to you (and which explanation might be most useful to you).
 
6:52 PM
What's wrong?  - Installing rdlowrey/alert (v0.8.1)
    Downloading: Connecting...    Failed to download rdlowrey/alert from dist: The "https://api.github.com/repos/rdlowrey/alert/zipball/f60617675c17f117c33ab7d2827ff1c230ad733d" file could not be downloaded (HTTP/1.1 404 Not Found)
    Now trying to download from source
 
Anonymous
@hakre How are they different? I always presumed right = true and wrong = false, in computing anyway.
 
Perhaps he is in a parallel universe where right = false and wrong = true?
:)
 
@Jay true/false is logic. wrong/right is a judgement.
 
Logic entails judgement.
 
Anonymous
@hakre But not in computing? In r/l you would be right, but a computer only knows logic does it not? The logic of a 1 and a 0 ?
 
6:55 PM
hi. @Jay .
how about Yes or No
 
Anonymous
@Rafee Hi there, how did you get on with your json?
 
In coldfusion, Yes & No are boolean.
 
@Jay in computing, a computer can't judge. so all it has are 0 and 1. I think this is called binary logic (-> boolean logic).
 
@Jay Still stuck and working on it.
 
Anonymous
@hakre which is what I mean, so in computing, right = true and wrong = false?
 
Anonymous
6:56 PM
@Rafee Anything I/we can help with?
 
yeah, its the same question as yesterday.
0
A: could not execute a file generated by php from terminal

prakharsingh95If the permissions are indeed the same, run this: diff -c normal.script php-output.script File names are self explanatory I believe.

 
@Jay let's do some quick text analysis: see this large document about the topic: en.wikipedia.org/wiki/Boolean_algebra search for both terms "right" and "wrong" and see how they are used (or not used at all).
 
Anonymous
@hakre Wikipedia, hmm..
 
That's no proof at all, it's just an example. let's say some logic calculation returns true.
the computer runs the software that has a function returning a boolean.
the function is called is_wrong().
this is why the boolean logic does not decide about wrong or right.
 
:-)
 
7:03 PM
It's a juxtaposition. It decides about truth value as it pertains to its primitives. The same way your neurons decide which signals to pass along based on limited information. Collective reasoning is still based on primitive reasoning. Not much difference really.
 
Anonymous
@hakre I'm trying to understand... aha. What I can't get my head around is if the return is true, does that not mean that the function is right? I'm not disagreeing, I don't have the experience to disagree, I'm just trying to understand.
 
Anonymous
@Rafee oo sorry, I thought your issue was with regards to json array, I can't help you with that one, maybe someone else here can though.
 
@ircmaxell what are your near future plans?
 
will share soon ;-)
 
k :)
 
7:07 PM
@Jay if you want to use boolean logic as a tool, it's you who define whether an expression / function / applicaiton that results to true either has a meaning of right, wrong or when arranged many of those true/false perhaps in a line of pixels on your display showing rainbow colors. is rainbow colors on the computer display now wrong or is it right? as it's only consisting of 0/1 and it's computing, please tell me as you said that 0 is right and 1 is true. :)
 
Thanks @Jay
 
Anonymous
@hakre AHAHAH, nice example (If I was from Texas and incredibly religious, I know what my response would be) but I think I see what you mean. So even though boolean responds with true, the 'function' outputting that could be checking if something is false or 'wrong' and thus outputting true. So it totally depends on what the function / expression / application is doing... right?
 
@hakre So if you believe the decision is left up to the programmer, why are you deciding for them that 2.5 == 2.0? By your logic you should simply explain what the sort function expects and leave it up to them to decide how to implement it. Rather than just advocating that $a - $b will do the right thing without explaining the consequences, right?
 
@Jay what the meaning of the boolean value is, yes.
@Sherif that's not what I wrote. I didn't decide that at all, which is an important difference. I only say how the function works and I leave it up to the user to decide how to make use of that functionality.
 
Anonymous
@hakre .. Thanks for explaining :-)
 
7:20 PM
Anyone experienced with Laravel?
And ADLdap, for that matter.
 
I know only one person insane enough to know about ldap. But not nearly insane enough to use laravel ;)
 
So.... no?
 
This interactive tutorial to learn new PHP7 features is pretty awesome! php7-tutorial.com
 
@Sherif who decides: the computer or the programmer who wrote the code? 3v4l.org/u7iHe
 
user image
19
 
7:24 PM
lol
 
Anonymous
haha
 
haha, damn good
 
heh
 
hahaha
 
user895378
that is amazing.
 
7:52 PM
@rdlowrey for you it's probably the inverse :-P
 
user895378
both are disasters :)
 
hehe
 
ThW
8:17 PM
@hakre I use a php callback that return a DOM document in XSLrunner
 
@ThW back then I was trying whatever I could imagine, but never tried that.
 
ThW
Actually I just return the DOMDocument instance (not a fragment), unlike the answer.
I needed a dynamic version of document() that I could use in a loop.
 
is that automatically imported into the current document then?
 
ThW
I don't think so. But xsl:copy should do it.
 
Anonymous
9:18 PM
i'm off, Gnight o/
 
9:41 PM
hey
Is there in php a function which can check if 2 strings are equal in charachters as in:
if acb is valid if abc is valid so the same charchters should be in both strings
 
@Ocramius PHP supports multiple unpacks in one call, you know
 
Maybe strcasecmp
 
@Duikboot You can implement it using strspn
 
thx!!
 
 
1 hour later…
user4920811
10:57 PM
can someone tell me, when I uploaded my website on the real server (not local), still should I use error_reporting() ?
 
user4920811
anybody there ?
 
11:12 PM
@stack Take a look in php.ini. It shows the recommended values to be used for development and production
 
user4920811
@Mike thanks
 
Why does require_once return true from second inclusion on? :-(
 
user4920811
I have a new question, what are .bak files in php?
 
@bwoebi Why wouldn't it return true? The file was successfully included the first time around.
 
@Mike I expected it to have the same return value than first inclusion…
 
11:19 PM
@bwoebi You mean it failed the first time?
 
@Mike no, it was successful.
 
@bwoebi Ah, I see. First time around returns int(1) and second time true?
 
@Mike for example.
int(1) is default return value of files
If you put a return $val; in the file, it will be the value of $val.
 
phpstorm 9 is out!!! annnnnnd nothing i've reported was fixed!!!
#fml
 
@RonaldUlyssesSwanson congrats! It will be in phpstorm 10 then!
 
11:22 PM
more like 11
 
user4920811
please tell me, what is a .php.bak file ?
 
@bwoebi I see what you mean. Interesting. Maybe it's a PHP bug.
 
@Mike I have no idea…
 
@bwoebi Same thing for include_once()
 
@RonaldUlyssesSwanson I noticed that PhpStorm 9 does basically nothing to support PHP 7.
 
11:26 PM
@Mike yeah, they're the same.
 
@Trowski doesn't even fully support 5.6
 
@Trowski yeah, stupid group use and keywords as identifiers still breaking everything.
 
@RonaldUlyssesSwanson Now that just makes panda sad.
Can't believe it doesn't fully support the only actively supported version of PHP ... lol
@bwoebi It gets really mad if you throw an Error too.
 
@Trowski 5.5 also is?
@Trowski what happens then?
 
11:29 PM
@bwoebi Hmm... I seem to recall a number of tweets implying otherwise (cause you can believe everything on Twitter).
 
@Trowski hah
 
Oh... I'm off by a day, sorry :P
 
:-P
 
@Trowski you can write stubs yourself :P
or even:
<?php

/**
 * @param int $dividend
 * @param int $divisor
 */
function intdiv($dividend, $divisor){}

const PHP_INT_MIN = 0;
 
@bwoebi It marks the file as invalid and underlines the throw in red.
 
11:34 PM
okay :o
 
Cause you're not throwing something derived from Exception.
 
ah obviously…^^
 
11:54 PM
@bwoebi There ya go. bugs.php.net/bug.php?id=70031
 

« first day (1726 days earlier)      last day (3226 days later) »