Using PHP 7 for a new project in 2017

Hi,

I fear the the title get me backlash from the Sitepoint PHP community. As the title indicates, I can’t decide whether or no to use PHP 7 for a new project starting in 2017. The project is regarding a website for a local business. I can’t decide because on one side I see a new article coming from Sitepoint daily and on other side so many negative articles on using PHP 7 on the internet. And since this is not a side project, I need to select to select the technology stack very carefully. Can someone guide me with the resources that can help me decide the thing?

Thank you.

Hi @Ganapathi004,

Can you post any examples?
I don’t know why PHP7 would be bad. It is supposed to be really fast compared to previous versions and it has a lot of new other goodies, it even has JSON array syntax and null coalescing operators so it event looks a bit more like JavaScript :slight_smile:
I have just started a new project with PHP7 and I cannot personally see any problems with that. PHP powers a great percentage of the web and it will still do so in the foreseeable future I think

2 Likes

Thanks @Andres_Vaquero.
Yeah even my first programming language is PHP two years back. But every now and then I see some posts advising not to use PHP. At the same time, I see companies like Slack which have PHP as their back-end tech. And as I didn’t have much experience to decide on the usage of a language, I posted this here.

You don’t say where you have seen these articles advising against PHP7.

Hi @Gandalf PHP: a fractal of bad design This is the main article that made me think whether I should learn PHP or not at all. I read on or two other articles but I couldn’t remember them.

That article is 5 years old, it pre-dates PHP7. And the whole argument about PHP being bad is and old one too. A lot of that is just opinion and preference, possibly based on old versions and people being fan-boys of other languages and feeling superior for using them.
If used properly I believe there is nothing wrong with PHP. But it can get a bad rap, I think because it is so popular and so accessible, it is used by an awful lot of people who don’t really know what they are doing, amateur programmers, producing amateur apps that may be insecure or whatever. This is not a short-fall of the language, but some of the people using it.

3 Likes

Thanks for clearing the thing @SamA74. Could you also please provide any resources so that I won’t be in the group of people who are using it awfully?

I think PHP would be a bad language for someone learning programming for the first time, but as a programming language after that I don’t see nothing wrong with it. My very first programming language was Apple Basic on the Apple II…boy do I feel old. :grin:

Anything from eevee that’s about PHP is generally always opposed against PHP. There are still a lot of talk and chatter as to why PHP is bad. A lot of the arguments seem to fairly be based on the fact that people who use PHP write bad code. Not necessarily the fact that PHP itself is a bad language. When people argue and refer to why PHP is a bad language, they’re usually arguing about people’s general layout using PHP. I’ve come across many questions like “Why is PHP a bad language?”

Usually, the other arguments is just what people hear and parrot. A lot of the arguments IMHO usually derive from people who have absolutely no idea how to write PHP and their PHP skills are generally lower than mediocre level in programming. Just like every other language, PHP have legacy codes.

Anyways, PHP itself is not bad. What makes it bad is the person who writes it. I mean suggesting a car sucks simply because of the car brand as opposed to people driving and texting and crashing with those cars are two fairly different response. First statement, the car is faulty. In this case, it would prove that PHP really is a bad lanaguage. But in reality, it’s people who text and drive while driving those cars and crashing them that gets the most attention. This basically means that it is the person who writes bad code that makes PHP have bad rap. Generally speaking though, since PHP is a loosely typed language, it allows for easy mistakes. I would really wish that the PHP team would just removed deprecated functions from all versions instead of keeping them. Maybe then, people would write PHP mre correctly.

1 Like

Thanks for the explanation @spaceshiptrooper. That gave me the confidence to start my project today itself. :smiley:

2 Likes

I think if there is any fault with PHP, it is that the documentation doesn’t stress security issues enough.
When looking at documentation for individual functions, it is easy to look at the example code without realizing that often a lot of “other stuff” is left out.
Analogous to reading on how to use a table saw without the instructions stating that safety goggles should be worn and the pieces clamped securely.

IMHO even if you don’t understand everything it says, you should give this a read before you start writing any code.

http://php.net/manual/en/security.php

3 Likes

I remember reading a comment some where. I probably was from the eevee article above. One of he argument was “If it’s not a bad language, no matter how much you slam that hammer into nails, that hammer would not break.” Basically saying that no matter how crappy you write code, to the author of that comment, it should not affect how the language runs. Pretty much saying that the author of this comment has absolutely no clue what the heck they are talking about. Metaphorically speaking, if you were to swing a hammer with enough force, it will break. This in turn means that enough terribly put together a code is, it will break the lanaguage or even lead to security issues.

2 Likes

I’ve written code in several languages, and speaking for myself, it is possible to write poor code in any language :blush:

For example, I’ve written code where if I had been better at the time:
I could have reduced several lines of code to one by using a native function that did the same work.
I could have prevented memory leaks by not polluting global scope with large non-garbage collectible arrays
I could have avoided runaway loops that timed out, or worse, crashed
I could have left better comments for my future self
etc.

Languages that are strongly typed / compiled do enforce better coding to a degree, but they are not fool-proof.

For me, even after years of writing code, I do not pretend to think that there is no room for improvement. I like to think I’m better than I was, but I know I’m not as good as I could be.

5 Likes

The second language I want to learn as of right now is C#. I wrote a program that checks to see if the game I am playing is running. If that game isn’t running, shut down my PC to save electricity. The thing is, I turn screen saver off. So I can stay online for a long time. In theory, this wastes too much electricity if I don’t play it. There are events where you have to be logged in for X amount of hours. So if he game isn’t running, it would be best to shut down the computer. However, I can’t do that in my sleep. So the idea of the program built in C# is to shut my computer down if for instance, the game crashed for some reason say Internet drops or the game is doing maintenance.

I basically put together a bunch of code that works and that does exactly what I wanted. However, it’s a memory hog. About half way through, it eats up 80 - 90% CPU. That’s because the idea of the program was terribly put together. And, it’s not written in PHP. It’s written in C#. So all languages, not just PHP can have terribly put together codes from a terrible beginner.


EDIT: And if I were to get into an argument with the author of the eevee article. I could simply use the same logic and common sense that the author has said about PHP.

Using my situation, I can say “It’s not my fault that my program is eating 80 - 90% of CPU. It’s C#'s fault!!! It’s a bad language because it allowed my program to eat 80 - 90%!!! LET US SPREAD FALSE RUMORS ABOUT IT!!!”

That’s EXACTLY how the author of the eevee article is arguing about PHP. It’s a shame that people like this parrot these kinds of false rumors and it’s a bit funny at the same time because I probably bet that this author has no idea what he is talking about when it comes to PHP. It looks like he doesn’t even know what mysql_real_escape_string is. Especially since mysql_* has been dead for more than 10 years.

3 Likes

Are you asking about PHP as a language or about version 7? If you want to use PHP then I’d suggest starting with the most recent versions since there is quite a bit of nice progress within PHP.

Other than that PHP is a very capable language and a perfect fit for web sites. The problem some programmers have with it is that it has a history of being dirty and without a consideration for any sane coding standards. This has changed a lot in recent years but some dirty stuff still remains. However, this is not an obstacle at all.

PHP may not be the best language to learn programming because it doesn’t enforce any rules, you can write any garbage you like and make it work. So for learning it’s good to have some experience in other languages or to simply read tutorials and take courses from experienced programmers.

2 Likes

@Lemon_Juice I was asking about PHP as the language. If I am using PHP now for a project (I will definitely! :slight_smile:), I won’t use any version other than 7.

1 Like

If you’ve decided to use PHP then you’ll have another important decision to make: which framework to use? This decision may even be more difficult! For any serious project a framework is essential because PHP alone does not offer you any structure for your application and you have to create it all from scratch. So you either need to choose one of the existing frameworks or write your own if you have enough experience. Choosing a PHP framework can be comparable to choosing a Linux distro :smiley:

My observation is that in the programming world most often not elegant tools become the most popular - just because they are available and easy to adopt by novice programmers, and in this respect a bad language can have an advantage because it doesn’t require any academic knowledge. It is simply very practical. The same with frameworks - the most popular framework, Laravel, is not really the best quality wise, but it’s relatively easy to use and has lots of support - in other words it gets the job done. Sometimes there are outright abominations like Wordpress, the most popular CMS (I think?) - poorly coded, resource hog, security failure, but still it gets the job done for most people.

Having said that, pure PHP really has lots of features for web sites or sophisticated online applications and if used properly it’s fast and powerful. Often a poor framework or system acts like a cage for a programmer and then it may seem that PHP is insecure or slow or bad in other ways. But once you get out of the cage it becomes really good. By getting out of the cage I don’t mean abandoning frameworks but moving to better ones - faster, more secure and more flexible.

1 Like

I think I have to do some research for that as well!

One of the main concerns is simply that a lot of commodity hosts are not using it yet. They don’t even have it available, especially many cheap cPanel hosts.
Obviously if the host doesn’t support PHP 7, that wouldn’t work. So make sure the future of your project will live in an adequate environment.

Second issue is, sometimes extra code needs pulled into the project that requires older support. Could be libraries or old API connectors or whatever it might be. If you get to use modern packages and create the code yourself, this isn’t an issue either.

Third is legacy framework. Similar to last point, if you had to use existing framework or CMS that wasn’t up to speed yet, then you are stuck.

Fourth point, in the reverse, if YOUR code has to be used in someone else’s project and they don’t support PHP 7, you’re stuck.

The argument is NOT about whether PHP is a good language, or that anything is wrong with version 7. The point is whether any of your environment or necessary dependencies need something older.

Only in very special situations where PHP is simply not the best tool, would you be having this conversation. PHP is not the language to use for desktop or mobile apps! There are situations where another language makes more sense. It’s not a gaming language for example.

I personally think over the vast majority of use cases for websites/apps, PHP and/or JS covers 90% of cases. Apps made from Java tend to be legacy systems. ASP/.NET can’t seem to get a good foothold and don’t offer much over PHP/JS. Node.js apps have their place but I don’t think all the bugs are worked out yet. Other popular languages; Rust, Go, whatever, even Python, Perl, have use cases here and there.

Which language is chosen tends to be less about how good the language is, and more about the style of programming. Do you like static typed or loose typed? Compiled or JIT? How good is the package manager and available packages? Is the community helpful and strong? Rarely is the question, “can the language do X?” Most languages can do most things!

If you are creating code which is to be distributed and used by anybody, you will be forced to say “PHP 7+” and thus lose potential market share. This is why Wordpress is still supporting like 5.2 or something crazy. So the greatest number of people can use it. This is also why it is not as optimized as it could be, not as secure, or as fast as it could be.

So never fear, if you go with PHP 7, then use it for what it is and enjoy the new features!

2 Likes

Apps made from Java tend to be legacy systems.

You have absolutely no idea what you’re talking about.

Java is the primary language used in most large scale places. Twitter, Amazon/AWS, Google, eBay, and Netflix are all Java shops. As well as many others. It is one of the most used languages used for large scale service code, making some of the most cutting edge software out there. Even if you’re not using Java in a large scale system, you’re probably using core functionality that is, like Elasticsearch or Kafka. If you wanted to pick a single language to entirely focus on, it is and still will be by far the safest and most well paid language to do that.

Node.js apps have their place but I don’t think all the bugs are worked out yet.

Also, a nope here. It’s fine. Used in production by many large scale sites. Been pretty stable for a few years now, actually.

If you’re writing web stuff and Node.js isn’t in your stack somewhere, at least at the build layer, then you’re probably doing something with legacy. It may not be serving clients, but it’s there.

At my job, on a total greenfield project, we actually use both Node.js for a serverside API Gateway and to better handle what little server rendered stuff our frontend needs, and Java for more performant, scalable, backend Microservices that are actually talking to our data store and doing the hard crunching of data.

7 Likes