Live data from Hacker News

PHP: The Right Way

phptherightway.com

181–190 of 233 posts

Re: PHP: The Right Way

#181
post #171

Earlier quoted context omitted.

really? add: floating point everywhere, objects that act like hashes but not exactly, fucked up scoping rules including global by default, the braindead Dom API, a severiously limited standard library, and brain damage coersions to the list...

I'd leave the DOM API out of it, that's not really the languages fault.

Well, its the first one hat offered it, isnt it?

Re: PHP: The Right Way

#183

As a part-time PHP hater who often has to work with it professionally, I believe this is a fantastic resource. The bit on databases in particular is something that all PHP devs should read. That said, it is difficult to bring a legacy code base in line with modern style, though you can improve it over time. Also, this could benefit from some other gotchas, extremely surprising behavior and best practices for avoiding…

On a database section, I am not a fan of PDO and I choose native interfaces like mysqli for my DAO layer or opt for something high level like ORM depending on the requirements.

But it goes without saying that protection from SQL injection is a must, it is just PDO's statement binding is not the only way. MySQLi does support data binding, and for others it is easy to DIY using sprintf and whatever is the escaping method target native driver implements.

Re: PHP: The Right Way

#185
post #127
post #78

PHP with these guidelines looks like JAVA to me, but without the relatively sane foundations. It is fun how much a very old moralist sentence by Confucius applies well to PHP. He said 其本亂而末治者否矣 which can be translated, in software language development context, as "Build a nice, reliable language on shitty definition? Bullshit!". (The word-by-word translation is "your - root - messy - and/but - leaves/result - governe…

This illustrates very common problem with people trying to criticize PHP. First you demand some "foundations". But if you look on virtually all existing popular languages, none of them were designed exactly in the form they are now. Java had tons of changes and additions, Python had object model change and now has new version that changed so much that it's not even backwards compatible, etc. etc. Does it mean they la…

That bug is not a big deal by itself, but the circumstances surrounding it are a symptom of severe problems with how PHP is developed.

Re: PHP: The Right Way

#186

Earlier quoted context omitted.

PSRs where decided based on the most common standards used by some of the biggest PHP projects around. It wasn't a single person setting a standard. PSRs are completely optional. However, you miss the point. The point of this isn't really to define all the options. Rather, it's to spell out best practices (and PSR-0 is really a best practice, and all about interoperability) that the community generally agrees with. B…

Im sorry but accepting underscores as a valid alternative to namespaces in 2012, is not a "best practice". The whole concept of PSR-0 is ridiculous anyway, because PHP supports registering multiple class loaders. If a project wants to use a naming convention that won't work with standard spl_autoload(), they can register their own autoloader.

except if you've ever had to work with lots of different autoloaders at once you'll know that you regularly get conflicts, and getting the correct autoloader order is often a case of trial and error. Using sane conventions across libraries avoids all of this mess.

Re: PHP: The Right Way

#187
post #153
post #142

Earlier quoted context omitted.

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…

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...

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

#188

Earlier quoted context omitted.

What bad design decisions have been made in PHP in the last 5 years?

Using '\' as a namespace seperator? Just off the top of my head, there are probably loads more.

I've actually gotten used to it (and I rallied against it heavily). It's really not so bad; it's even somewhat nice it has a file-system like connotation. PHP's design precluded using any existing operators.

Re: PHP: The Right Way

#189
post #140

Earlier quoted context omitted.

Sure, but you defined ptr outside of the loop. Who defined $object outside of the loop in the PHP example? Also note that, in C, you have to explicitly dereference pointers: ptr = 42; You should get a warning from your compiler if you try that. PHP effectively goes ahead and changes it to: *ptr = 42; Perl requires you to explicitly dereference references as well: @array = ('c', 'c++', 'java', 'perl'); $item = \$array…

You think PHP is weird because you don't understand references. Reference is not a pointer, PHP doesn't have pointers. Reference is variable binding. $a =& $b is not an assignment. It is a binding - it means $a and $b are now bound to the same variable/value.

No, I do understand references. I'm just trying to explain how references in PHP are very, very different from references or pointers in any other language I'm aware of, and how they could be confusing to people who know other languages well but are less experienced with PHP.

Perl does have a similar concept, but it calls it aliasing. Perl references behave more like what you'd expect coming from other languages.

I wish PHP had called its references something else. They're not really references at all.

Just because I think PHP references are weird doesn't mean I don't know how they work. It does make me wonder, though, why PHP references work the way they do. What's the benefit of doing it this way instead of the way just about every other language ever does it?

Post reply on HN