Live data from Hacker News

PHP the Wrong Way

phpthewrongway.com

81–90 of 194 posts

Re: PHP the Wrong Way

#81
post #7

Earlier quoted context omitted.

The very existence of PHP is a contradiction, so I wouldn't sweat to much about it. But speaking of boolean logic, negating "always use a framework" does not yield your interpretation.

"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…

Coming from a C background I used to hate PHP as it's inconsistent and flaky to the point of schizophrenia. Same applies to library naming. It positively encourages bad design and inconsistency. C wasn't and didn't.

Nearly all PHP I came across was the mess of some self-taught stumbling way beyond the point they should have been screaming for help, and going back to photoshopp. The docs don't exactly help here (may have changed, it's been a few years) as the apparently helpful comments on each feature aren't moderated in any way and are frequently unhelpful or plain wrong - but they're left to encourage the unwary.

I don't disagree it's perfectly possible to produce decent code with a good coder, and good principles applied to the project. I've seen some very clean looking PHP, and OO classes. That's been because they know the problems of the language and have been careful around such areas, or tried to avoid them entirely. I've worked on a couple of PHP based projects where I couldn't say a word against it as they'd used it well from the start.

We are where we are, but I would have been happier if the tool most often used by "web developers" stumbling in was a little more constrained and consistent about it.

Re: PHP the Wrong Way

#82
post #8
post #5

Earlier quoted context omitted.

It's definitely not a satire. They are some valid points. It's not against using frameworks. I think it's more about finding the right solution for the problem.

What I take from is not to use PHP, which I do as it pays the bills, but why would anyone choose it for a new project baffles me. This article doesn't help it.

I love PHP. It feels like a complete toolbox to me, whereas other languages like Python or Ruby feel like I'm buying an entire Home Depot for every project. Sometimes you need the whole store. Most times I don't.

I think the OP has some good points about reconsidering the standard answers that everyone gives to questions when asked. There are no silver bullets in web, but many things sure are treated like them.

Maybe there are projects where PHP isn't right. There are probably tons. But that doesn't mean that it's always wrong. PHP is what got me into making web things in the first place. I loved (and still love) how utilitarian it can be.

But perhaps that's where I differ from most people. I see myself as someone that makes web stuff. Most seem to see themselves as app creators or system builders. And they probably are. Sure, I do that too when the time comes, but if most of the time I'm building a front-end to a CMS, I'm hardly "engineering" anything. I'm mostly just trying to make specific art for other people.

Anyway, I don't understand why PHP would immediately be ruled out from this article. It feels like the JavaScript of the server-side world to me. Use as little or as much as you want. You can do awful things with it, but also wonderful things.

Re: PHP the Wrong Way

#83
post #61

IMO one of the key missing points here that is not really considered, is that when you use a well documented and relatively mature framework, it greatly simplifies some of the non-programming related aspects of software development, particularly with regard to getting new developers up to speed, and ensuring that even your junior-most developers are able to contribute without having to become heavily acquainted with…

Well, I always write a command line (CLI) program first, without worrying at all, about what kind of user interfaces (UI) I may do later on.

Frameworks do it the other way around. They generate a skeleton for a web user interface or a mobile app, and next, the real program gets unidentifiably shoehorned in.

There are so many different ways to call a program function: by the user, by one of your own scripts that does it in batch, by an external program through an API, through a web user interface, by a mobile app, by a desktop app, ...

Isn't the most stupid way of building a program, to shoehorn it into a web user interface? It pretty much guarantees that you will have to implement the same logic many times all over again. That kind of applications can never be consistent.

Furthermore, my CLI programs are trivially easy to containerize properly with tools like docker. How can you do that with a monolithic framework monster?

Re: PHP the Wrong Way

#84

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.

>Isn't a security one of the gains of using frameworks, That depends on the scale of what you're building. Generally I would agree with you, but if you building some small, something that would only ever use a small subsection of whatever framework you pick, then you could end up having more issues than if you didn't use a framework. Just because you aren't using parts of a framework, doesn't mean that security issue…

> It's going to be a whole lot easier for you to lock those two queries down, than securing an entire ORM.

If it's a competent ORM then it shouldn't even expose any way to not use prepared statements, for example.

Re: PHP the Wrong Way

#86
It is near impossible to write "Modern" PHP and achieve good performance.

On every request, PHP reads and parses every file that is referenced somehow. It is in direct contradiction to the language constructs the PHP itself provides - especially Exceptions, Interfaces and Inheritance.

People want to use these features, because they help design better systems, where the concerns are separated, and features are plugins instead of hardcoded all over the place.

Unfortunately, the required files for a request can pile up quite quickly, to the point where bytecode cache does not help, serving multiple requests per PHP load does not help, prewarming cache for frontend such as Varnish does not help, memory usage is over the roof because of trashed heap memory.

So, to sum up, the author here is right: this is insanity, until PHP provides a module system that can handle PHP abstractions.

Re: PHP the Wrong Way

#88

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.

Most of security threats a small project encounters are very low-effort and concentrate around automatic checking for known exploits in widely used technology. Your site will be probed for known vulnerabilities a lot; but probability that somebody will actually invest his time in searching for SQL injections in your custom code is much lower.

Re: PHP the Wrong Way

#89

Is it me or is the author confused about the distinction between a library and a framework? To me, a framework implies inversion of control: you don't call the framework's code; the framework's code calls your code. Granted, he skirts the issue with phrases like "A framework is a system that helps you build software, but at the same time it forces you to work within the limitations and restrictions of the framework i…

> Maybe I'm overstepping my bounds, but this article is furthering certain stereotypes about PHP-programmers.

You probably are. You'd make a better case if you were actually discussing http://www.phptherightway.com/.

Re: PHP the Wrong Way

#90
post #54

Earlier quoted context omitted.

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…

They removed mysql_real_escape_string function so that you can use mysqli_real_escape_string http://php.net/manual/en/mysqli.real-escape-string.php

No, you use PDO::quote().
Post reply on HN