DEV Community

Cover image for Pitch me on PHP
Ben Halpern
Ben Halpern

Posted on

Pitch me on PHP

Part of a new series! Feel welcome to dip in and weigh in on a past question.

Let's say I've never used PHP before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.

Latest comments (74)

Collapse
 
norflin321 profile image
norflin

do not touch it.

Collapse
 
hollyw00d profile image
Matt Jennings • Edited
  • In genera writing PHP is way shorter than writing Java or C# which are usually more verbose.

  • Some sources say over 75% of websites run on PHP.

  • Some sources say over 30% of websites use the WordPress framework, which is written in PHP.

  • Even visualstudio.microsoft.com/ is a WordPress site and therefore written in PHP. Way to go Microsoft!

Collapse
 
willypuzzle profile image
Domenico Rizzo

PHP, in the its recent version, has become very riable. And it offers the flexibilty of a dynamic type language with the secureness of a strong type language. With PHP you can do, in a single line of code, what Java requires very more lines of code. Besides with the framework Laravel, if it used properly, you can do very ordinated and well organized projects. The problem is that with PHP you can easy break the rules of a well structured programming, so you could do a mess if you don't pay enough attention.

Collapse
 
jacekandrzejewski profile image
Jacek Andrzejewski

Pros:

  • gradual typing (you can ignore types and add them over time later)
  • std library with many useful functions that I wish c/c++ had this easy to use
  • evolves pretty fast
  • very fast (vanilla php+nginx can respond with hello world in 4ms, going with Laravel under 50ms doesn't require much work)
  • steals good syntax from other languages
  • has magic and metaprogramming (read up on __get, __invoke and "Variable variables")
  • good docs
  • great dependency manager (composer)
  • amazing tooling (code style, static analysis and amazing automated refactoring where you can migrate big project between frameworks in a week [Rector])
  • multi-paradigm, so you can be OOP or functional (kind of)
  • has traits (like mixins

Cons:

  • magic and metaprogramming can make code extremely hard to read and debug [as example you can call function by "functionname"(args)]
  • default type casting
  • legacy code is so bad that satan laughs whenever someone has to work on it (or maybe he wrote it)
  • sometimes inconsistent, sometimes consistent
  • quite a bit of legacy syntax
  • pure php tutorials online are mostly outdated by 10 years at least
Collapse
 
liviufromendtest profile image
Liviu Lupei

We all know PHP gets a lot of hate.
But it makes it really easy for a beginner to build a web project.
You might hear Junior Developers saying that PHP is slow, but they might forget that Facebook ran on PHP for a long time, and they're still using it in many components.

Collapse
 
mono13th profile image
Moch. Sudharmono

Wordpress uses PHP!

Collapse
 
saadchaay profile image
Saad Chaay
  • 1 It’s an Open-source Language
  • 2 It is plain-sailing to use
  • 3 Upgradation in PHP software is a lot easier
  • 4 PHP resources are obtainable easily
  • 5 PHP Web Development is Cost-efficient
  • 6 PHP language helps to decrease the time of web development
  • 7 Codes include high flexibility and adequately simple integration feature
  • 8 PHP programming language also helps in web hosting
  • 9 High-performing PHP websites help businesses to retain customers
  • 10 Development Time is Less with PHP
Collapse
 
darkain profile image
Vincent Milum Jr

There is a lot of aggressive hate for PHP for all the wrong reasons (most all link to the same article written over a decade ago that mostly doesn't apply to PHP today, or things that apply to all interpreted languages equally)

Beyond that, I'll say this: PHP has the most enterprise friendly features of any of the major languages out there today.

Yeah, I'm going to get flack for this, but it from decades of experience maintaining systems that need 100% uptime.

PHP has the absolute most enterprise friendly MySQL connector outside of the C language itself, while still having the nicety of easy string manipulation. PHP has the most graceful support for distributed SQL databases with its connector, being able to handle database server failures better than any other language.

I'll admit, I'm kinda biased in this regards, however. As I'm the one that helped bake in some of that functionality. There are some extremely rare bugs in MySQL/MariaDB that can entirely hose an application server. I had one of these such bugs take out an entire fleet of application servers, getting them all in a locked state, essentially the DB DoSed the application servers.

Thanks to some of the additions I helped with to implement in PHP's connector, this is no longer an issue if the connector is configured properly. However, these same fixes don't exist in other languages like Python or JavaScript. DevOps generally just rely on "oh, it broke, let's reboot and hope it doesn't happen again" instead of doing the full investigation into the language's source code itself, the connector, and the database's source code.

Having done all that work, I know undoubtable that PHP can handle a fair bit number more failure scenarios than other languages, having done this at scale for 15+ years.

So yeah, if you're just starting out and have a single app server and a single database and rebooting them is fine, then maybe this isn't an issue. But if you're running thousands of servers at scale and need reliability and uptime, PHP's ability to horizontally scale easily mixed with its MySQL connector's ability to gracefully handle more situations makes it prime for very large workloads.

Its not obvious up-front, but PHP has more enterprise grade features than just about anything else out there.

Collapse
 
johnhalsey profile image
John Halsey

PHP is a great language to use and works fantastically with frameworks like Laravel.

PHP is good for beginners and my favourite thing is that the name PHP is, itself, recursive.

Collapse
 
nashpl profile image
Krzysztof Buczynski
  • easy to use as long you have basic programming experience but hard to master
  • Laravel is a thing
  • comes with Ubuntu which is preferred OS i work on.
  • Telling people that I do PHP make them cringe and it hilarious
  • rich community
  • perfect server side language in my opinion
Collapse
 
jeydotc profile image
Jeysson Guevara

Do you consider yourself a good engineer? Well, this is the chance to demonstrate it. Here's a language that has almost no rules, you can make real atrocities and yet make it work. The only thing that separates a horrendous, lovecraftean mess from an elegant and well engineered solution is YOU.

Collapse
 
jovialcore profile image
Chidiebere Chukwudi

Do you know that "php" is pronouced same way backward ?

Collapse
 
bobbyiliev profile image
Bobby Iliev

In addition to what has already been mentioned, this guy here levelsio makes $3.15M per year from a couple of SaaS projects, all written in PHP and often just a single index.php file. Pretty impresive for a language that "dOEsn'T sCAle".

Collapse
 
golangch profile image
Stefan Wuthrich

For PHP you can finde the best Job Board for PHP Jobs
Just the code running the board is NOT starting with <?php ;-)

Collapse
 
taufik_nurrohman profile image
Taufik Nurrohman • Edited

You can have class, constant, function, method and property with the same name.

$foo = new foo(); // class `foo`
echo foo; // constant `foo`
foo(); // function `foo`
$foo->bar(); // method `bar`
$foo->bar; // property `bar`
Enter fullscreen mode Exit fullscreen mode