Live data from Hacker News

PHP the Wrong Way

phpthewrongway.com

31–40 of 194 posts

Re: PHP the Wrong Way

#31
post #21

I do not want to be mean, but I honestly feel there is no 'right way' in case of PHP. There are communities that care about 'doing it right' and there are some that want just to 'get the job done'. I prefer the former, PHP always seemed to prefer the latter.

PHP has been to me and continues to be the most stable platform to build websites upon. Development and deployment are extremely simple, it is rich in functionality and if you know what you're doing, you can write just as reliable and secure code as you can in any dynamically typed language.

Re: PHP the Wrong Way

#32
post #21

I do not want to be mean, but I honestly feel there is no 'right way' in case of PHP. There are communities that care about 'doing it right' and there are some that want just to 'get the job done'. I prefer the former, PHP always seemed to prefer the latter.

This is a massive overgeneralisation of a humongous amount of people and man-hours of work. Why do you feel this? Do you have anything to back up this statement? Anecdotally speaking, I'm a Senior Software Engineer working with Go and PHP. We use Go when working on performance critical code, because for us that's where it excels. We use PHP when we need simple interoperability with the legacy Magento site our company…

Well said

Re: PHP the Wrong Way

#33
post #28

Earlier quoted context omitted.

This is a massive overgeneralisation of a humongous amount of people and man-hours of work. Why do you feel this? Do you have anything to back up this statement? Anecdotally speaking, I'm a Senior Software Engineer working with Go and PHP. We use Go when working on performance critical code, because for us that's where it excels. We use PHP when we need simple interoperability with the legacy Magento site our company…

99% of people who get paid to write PHP do not have the requisite level of patience, process, or experience to write a fibonacci method let alone write "truly beautiful" PHP.

It's really easy to make up statistics on the spot with absolutely no source.

I very much doubt that people would be getting paid to write any code if they couldn't implement a single for loop in their primary programming language.

Re: PHP the Wrong Way

#34
I didn't read it all but some people are do dogmatic about things it is stupid. I have dealt with plenty of co-workers who read some book and promptly beat everyone with it.

Re: PHP the Wrong Way

#35
post #20

Earlier quoted context omitted.

You may be drowning in the kool-aid. It is very easy to write tiny secure code in PHP without a framework. Of course if you're building a social network, then it will run into some of those potential security issues. But for most of the small problems you're using PHP to solve, you really don't need to be a security expert as long as you're not piping user input directly to your database or OS. It's kind of the point…

No it's not easy. You need to be sure you escape everything, setup a mecanism for allowed host, CSRF, anti click-hijacking and of course ensure your auth workflow is nicely designed. And that supposes that not only you know about it, but also how to implement it properly. Not to mention the time to code it, document it, test it and maintain it. Most custom PHP site I encounter are full of gigantic holes. And then oth…

If its under 50 lines of code for some simple processing, I don't think another developer who comes in would have much trouble. Of course if that 50 lines of code is now 250 because it tries to get around a framework, then instead of finding a PHP developer to help out on the code, you now need a $framework developer.

Basically, don't use a framework unless you really do need all the features it gives you. Don't just pick a framework and try to cram your code into it for the sole purpose of using a framework.

Re: PHP the Wrong Way

#36

Earlier quoted context omitted.

"The very existence of PHP is a contradiction" Uhm no for me coming from a C background I love PHP since its basically C with a lot of the boring/repetitive stuff abstracted away Good PHP code exists, it only got a bad name due to "web developers" with no formal programming education stumbling across PHP and going "aha this can generate my html etc" and then proceeding to make a pile of mistakes. PHP is a hammer, bla…

PHP (the interpreter) used to be filled with bugs, design flaws and incoherences. It got better lately, but IMO it still caries a huge mess of legacy stuff that shouldn't even exist (mysql_real_escape_string anyone?) In this case, both the hammer and the hammer's user can be blamed.

PHP7 has removed a lot of the old cruft and made some small improvements to PHP's idiomatic syntax.

One great example is the removal of the mysql_real_escape_string function. http://php.net/manual/en/function.mysql-real-escape-string.p...

Another is finally giving us a null coalescing operator, which is a solution for a constant pain point in dealing with raw PHP POST and GET parameters.

The full "new features" list of PHP7: http://php.net/manual/en/migration70.new-features.php

The change log of PHP7+: http://php.net/ChangeLog-7.php

Re: PHP the Wrong Way

#37
post #15

So the author considers following PSR guidelines beyond 1 and 2 to be "the wrong way"? PSR-4 is the currently accepted best practice for autoloading and while it "may [have] a direct effect upon how you code your software," it's the optimal approach for 99% of projects I've encountered. Following community interoperability guidelines is what allows developers to move away from monolithic frameworks and compose projec…

> currently accepted best practice for autoloading

According to who? FIG?

Are you aware that php has a built in auto loader that supports namespaces and is written in C?

> compose projects based on the packages they need.

Ah, the NPM/Composer golden brick road to development. Aka, the "I don't know what this is but I'm gonna lick it" approach to development, where you end up with 50 "micro-frameworks" or "utility libraries" each of which depends on a further 20 other libraries.

I have some issues with this site but it's right that the FIG is a joke, and anyone who claims its "best practice" is not paying attention.

Re: PHP the Wrong Way

#38
post #20

I just skimmed the website, and I am still not sure if it's meant seriously or if it's some kind of joke? Feels a bit contradictory eg. "dont use framework" vs "make software secure by default". Isn't a security one of the gains of using frameworks, beside other things? You would need to be a security expert to cover all potential security issues when writing something from a scratch.

You may be drowning in the kool-aid. It is very easy to write tiny secure code in PHP without a framework. Of course if you're building a social network, then it will run into some of those potential security issues. But for most of the small problems you're using PHP to solve, you really don't need to be a security expert as long as you're not piping user input directly to your database or OS. It's kind of the point…

> It is very easy to write tiny secure code in PHP without a framework

Actually it isn't, like at all. A open source framework will always be more secure than the code you "easily write", because a larger pool developers can review,audit,test and fix that code.

Re: PHP the Wrong Way

#39
post #15

So the author considers following PSR guidelines beyond 1 and 2 to be "the wrong way"? PSR-4 is the currently accepted best practice for autoloading and while it "may [have] a direct effect upon how you code your software," it's the optimal approach for 99% of projects I've encountered. Following community interoperability guidelines is what allows developers to move away from monolithic frameworks and compose projec…

> currently accepted best practice for autoloading According to who? FIG? Are you aware that php has a built in auto loader that supports namespaces and is written in C? > compose projects based on the packages they need. Ah, the NPM/Composer golden brick road to development. Aka, the "I don't know what this is but I'm gonna lick it" approach to development, where you end up with 50 "micro-frameworks" or "utility lib…

> Are you aware that php has a built in auto loader that supports namespaces and is written in C?

What are you referring to?

Re: PHP the Wrong Way

#40
post #28

Earlier quoted context omitted.

99% of people who get paid to write PHP do not have the requisite level of patience, process, or experience to write a fibonacci method let alone write "truly beautiful" PHP.

It's really easy to make up statistics on the spot with absolutely no source. I very much doubt that people would be getting paid to write any code if they couldn't implement a single for loop in their primary programming language.

PHP was the first language I ever used professionally. The code I wrote - the code every single one of my colleagues wrote - was atrocious. We were paid bottom dollar ($30k in 2008) to write absolute shit code. The PHP community in my area was the same. All newbies, all paid barely more than a fast food manager, all writing code that could be taken down by a HS student with Fiddler.

I'm sure different experiences exist, but the majority of folks who I speak to have experiences that match mine very closely.

PHP is a ghetto.

Post reply on HN