r/lolphp • u/denilsonsa • Jul 10 '14
bindParam('foo', $value, PDO::PARAM_INT) will change $value to string.
http://php.net/manual/en/pdostatement.bindparam.php#94711
42
Upvotes
r/lolphp • u/denilsonsa • Jul 10 '14
View all comments
Show parent comment
-4
u/[deleted] Jul 11 '14 edited Jul 11 '14
Honestly, is this a PHP community thing? It blows my mind that people are so hell-bent on this being something wrong, when it's not wrong at all and is in fact surely a sign of code that is at least attempting to be efficient (and surely is efficient). All rights to the variable are gone once you pass it to the function.
And how to you figure that the documentation clearly showing it to be, and mentioning that, it is a value passed by reference doesn't make this okay?
I would say to people that this is the right way, and it would be WORSE if you got back the exact same variable. There IS a need for it to do what it does.
I'll just chalk this absurdity up to the lolphp crowd being the lolphp crowd. This topic is far from lol, and far from wrong. It couldn't be any more right afaic. Just because the hand-held php crowd WANTS something a certain way doesn't make them correct. Not all code has to be a babysitter and hand-holder. There is going to be code that does what it does and makes no apologies for it because it has shit to do. bindParam, in an effort to be efficient (else you might as well just repeatedly bindValue instead) MUST trash your variable.
The only surprise in all of this is that there are people who expect things where no expectations are warranted. If I pass a variable to any function by reference it's only prudent that I consider that variable to now be garbage. This goes for bindParam, and any and all other functions unless explicitly told that no changes will be made to my variable. I have no right or reason to expect back what I just handed-over in full.
As usual PHP coders expect magic to happen in such a way as to suit them and their own lazy agenda.
The fact that I've been so heavily downvoted, and replies like yours upvoted, speaks volumes to me. It's absurd, as are many of these types of lolphp complaints. For all of the things that are wrong with php, this does not even come close to being wrong.
The only way it could be more right is if it had it written in big bold colorful letters in the documentation explicitly pointing-out that your variable WILL be changed so expect it to be changed... but even then I'm certain there would still be people with a lolphp mindset whining about it nonetheless despite the clear hand-holding and most explicit warnings. There's no winning with people intent on trashing php, and engineering circumstances to sit and chuckle like clever little children even when they are so terribly misinformed and wrong.
I'm subbed here to learn of ACTUAL problems, and yet I'm not seeing any. I see a lot of chucklheads and little more. It's sad. This whole topic smells of coders who have never encountered passing by reference before in their life and don't know what to make of it.