News for hackers. Stuff that matters.
Re:PHP: The Right Way by ufo on Sunday July 08, 2012 @12:58AM (#4213691)
WTF. Sometimes I wonder if I'm being unfairly prejudiced by not learning PHP myself and making my own decision about it but things like this make me change my mind.
Re:PHP: The Right Way by smsm42 on Sunday July 08, 2012 @01:58AM (#4213813)
You are completely correct - you are being unfairly prejudiced by judging PHP on explanations of people that do not understand it instead of learning it. If you learned it, you would know references work exactly like they supposed to, and do exactly what they are meant to do - just because they are not, as parent assumes, pointers, he misunderstands them and thinks they are weird. Moreover, he thinks since PHP in not like C and does not have C-like pointers PHP is weird. Please read http://us2.php.net/references if you want real information instead of collection of misunderstanding.
Re:PHP: The Right Way by ufo on Sunday July 08, 2012 @03:38AM (#4214003)
I think the whole point here is why does PHP even have references like that. Right now the only mainstream language I know that does that is C++ and well, its C++ and mutable references are actually not frequently used in practice. Most other languages stay with pass by value most of the time and PHP references kind of look like a leaky abstraction from the underlying C implementation...
Re:PHP: The Right Way by smsm42 on Monday July 09, 2012 @03:39AM (#4217126)
C++ references and PHP references are completely different beasts. PHP references like Unix hardlinks, for example. As for why they exist - they make doing some things easier and some use cases easier to program, without introducing concepts like pointers which are completely foreign to language like PHP. Could we do without them? Yes, probably. That's only one way to solve it, there can be others.
Re:PHP: The Right Way by LnxPrgr3 on Sunday July 08, 2012 @01:21PM (#4215030)
And in C++, a variable is either declared as a reference and acts like one, or it's declared as a value and acts like one. It can't change behavior halfway through a function.

(Well, ignoring operator overloading anyway… you could conceivably import PHP's concept of variables and references into C++.)

Re:PHP: The Right Way by xd on Sunday July 08, 2012 @11:56AM (#4214853)
I use references for passing around large arrays of data for instance, rather than having copies made all over the place (class instances are passed by reference no matter what you do).
Re:PHP: The Right Way by ufo on Sunday July 08, 2012 @05:21PM (#4215763)
What I meant is that people usually pass things via a pointer (that needs to be explicitly dereferrenced) or via const references (where there is no mutation to worry about). Mutable references are rarer and usually they are function arguments and are relatively "obvious"
Re:PHP: The Right Way by mikeash on Sunday July 08, 2012 @08:00PM (#4216117)
I thought this for a long time as well. I always enjoyed ragging on PHP but wondered if it was just because I wasn't familiar with it.

A few months ago, I got the opportunity to do a little PHP programming. I was wrong. I didn't have a bad impression of PHP simply out of ignorance. In fact, my opinion of the language is now much lower than before. I honestly can't conceive how anyone could legitimately defend it for anything other than its ubiquity.