DEV Community 👩‍💻👨‍💻

Vinicius Ithalo
Vinicius Ithalo

Posted on • Updated on

Adventuring Into PHP

I'm planning to start a series of posts showing my first impressions as someone inexperienced in programming who had his first impressions in Python. I'll try to post every time I finish studying so that the original feeling is still clear.

So, I decided to learn PHP

While messing around on Discord, I found a discussion about this language and how it was useful in web development. It wasn't very long and not all that interesting, but they said something that really caught my attention.

Screenshot of the discussion

I really like python and my focus is on web development, so why not try it out?

This thought was what made me start looking for online resources, a task that apparently I'm not intelligent enough to do, so I asked on Discord.

What is PHP

PHP is a scripting language specialized in web development and that can be embedded inside HTML and is executed on the server, meaning no shady scripts running on the client computer and more freedom working with sensitive data.

Installing PHP

XAMPP interface
PHP can be manually installed by itself, or so I was told, but the easiest way when learning is through those already configured packages, like WAMP, LAMP and XAMPP. People from discord recommended using XAMPP, so I'll be sticking with it for now. Having installed it, everything left is understanding how it works.

Top comments (26)

Collapse
 
valeriavg profile image
Valeria

TL;DR Please don't. Try Go or Nodejs instead.

I've gone the same way some 10 years ago.
PHP stack was one of the most frustrating things I've ever seen. The way PHP is executed won't even give you a glimpse on how HTTP servers are built as it depends on external running server like Nginx to work. And yes you'll need to learn how to configure said Nginx too.
Go is much more like Python in its core values, but better in performance and syntax among other things. Very easy and pleasant to write and produces enterprise quality apps. If your goal is to expand your knowledge and experience beyond serving HTML and dive into how the web it built in 2021, Go is the way.

Nodejs on the other hand, will give you an opportunity to write server-side rendered websites with front-end technologies like React or Svelte.Try Nextjs or Sveltekit to build something fast. JavaScript has some flaws, but if your goal is to build websites that'll be a wiser choice than PHP.

Whoever told you to learn LAMP stack were either trolling or absolutely oblivious. Unless you're doing it strictly for research purposes, drop it, it'd be like buying an audio cassette.

Good luck on your journey!

Collapse
 
xwero profile image
david duymelinck

If you only did php 10 years ago, you should not comment on the current state of php development.

It is true that 10 years ago php was a wild west language, but that has changed over the years. Frameworks matured, the language matured.

It is true that you can't run php without a webserver, but for me that is a plus. You can choose between apache, nginx, caddy or whatever webserver will come along that handles the http requests.

If you want to create websites, you are not going to find a lot of packages that have e-commerce or CRM or CMS functionality in go or javascript. And most of the sites are just that or a combination thereof.

PHP and whatever websever/database stack you choose is good to start with web development.

So please stop looking down on PHP as a valid programming environment.

Collapse
 
valeriavg profile image
Valeria

I commented on the current state of web development.
Why would you want a separate server if you can write one with two lines of code, including an import?
True, PHP community came up with a lot of great things that make it easier to achieve similar functionality to the other languages. Except modern languages already come built with it, along with far better performance and development experience.

With all my respect to C, I wouldn't recommend anyone learning it today either, because there's Rust.
With all my respect to Java, I would suggest to build an Android app in Kotlin instead.
With all my respect to Objective C, I would suggest to build an iOS app in Swift.

Good thing you've mentioned CMS, because the only advantage of learning PHP would be the ability to operate some Wordpress, Drupal or ModX site. Sure with a lot of tinkering you can even scale it! What you get for it? Ability to use jQuery-based templates and a chance to drop your production site after a plugin update.

Do I need to mention type checking? TDD? Low-level protocols?

But you're right! I'm not a PHP expert and it's time the developing community would stop laughing on it!
Please write a post why one should learn PHP today, what makes it better than other languages and why I am wrong.

And it's okay if while making a research for the said post you'll find out that there are much better tools and you'll change your mind, because the tech develops very fast and the needs change constantly and so we as developers also need to evolve to stay relevant.

Thread Thread
 
xwero profile image
david duymelinck • Edited on

Stop writing things that just aren't true anymore.

There are multiple CMS solutions based on mature frameworks, for example boltcms.io and sulu.io.

Type checking is in php since version 7 and we are now on version eight. TDD is the default way to code now.

True, Drupal and Wordpress have been slow to follow good practices, but they are catching up.
The frontend is anything you want it to be because both CMS solutions provide a headless option now. So all the work can happen on the backend if you don't like how the CMS renders the pages.

True go is fast but it shines on things like docker and caddy, not for websites. If that was the case why are there more success stories about go websites?

Javascript development is the wild west for me. Every few months you have to rewrite your code, or is there a new shiny thing. My opinion is that virtual dom should be a thing of the past because of the new javascript features and browser APIs.

I'm aware of the new languages and solutions. But i keep going back to php to produce solid websites. I'm very pragmatic about the languages I write code in. If one is better that the other i'm not going to use the less fitted language.

Thread Thread
 
valeriavg profile image
Valeria

So what makes PHP a better language?
I agree with the virtual dom part, hence Svelte.
You don't need to rewrite your code because there's a new thing, you need to rewrite your code because there are new requirements or a better approach.

Thread Thread
 
xwero profile image
david duymelinck

For me PHP makes the most sense for websites, because there are so many packages that makes building websites faster. So it is more about the solutions that are written in PHP than the language itself.
That is the case for every language I think. If you start with ML python is a good fit because there are so many good packages.

You are right you don't need to rewrite the code every time a new feature is introduced. But there will come a time when you have no other option than to update. If the features are added at an insane speed the time you need to update will be faster. And it will feel like you are only rewriting old code. I have been in that situation before.

Thread Thread
 
valeriavg profile image
Valeria

Please don't get me wrong here, but that's exactly my point.
It might be good for making websites, but not for making SaaS, API, web services, distributed systems, content delivery networks, real-time applications and so on.
Can you write a website in Go? Absolutely, would be even easier than in PHP
Can you turn that website into a scalable enterprise system spanning across continents? That would be very very very hard to do in PHP
So I don't see why a person who just started its development path should settle for something that doesn't work well in modern world

Thread Thread
 
xwero profile image
david duymelinck

No language fits all applications.

Scaling is not about the fastest language. It is about load balancing, redundancy, and so on. No language provides this out of the box.
PHP is well equipped to be scalable because it doesn't runs like a go app, so memory leaks are a rarity.

I don't know in which modern world you live, more than 70 percent of the websites run php. This is also the reason a lot of code is written in PHP.
It's like in javascript a lot of react code is written because a lot of people jumped on that train.

If you want to write good code lisp languages are the way to go. But if you want to get a website up and running fast and with confidence you look at the languages/frameworks a lot of people use.
If you want to learn programming it doesn't matter which language you use because most languages support multiple paradigms. In that regard languages today are more interchangeable than ever before.

I just don't understand why you keep looking down on PHP, it is a tool in your toolbox if you know it.

Thread Thread
 
valeriavg profile image
Valeria • Edited on

w3techs.com/technologies/details/p...

  • PHP is used by 78.1% of all the websites whose server-side programming language we know.
  • Around 30% of these use PHP 5 and below
  • PHP version 7 is used by 54.4% of all the websites whose server-side programming language we know.
  • WordPress is used by 65.1% of all the websites whose content management system we know. This is 43.0% of all websites.

Hence in the great majority of the cases PHP is used in connection to WordPress.
A CMS targeted at people that are not coders. From the amount of web sites which are insecure enough to disclose their backend technology.

Did you mention memory leaks?
scoutapm.com/blog/php-memory-leaks...

Memory leaks can happen in any language, including PHP. These memory leaks may happen in small increments that take time to accumulate, or in larger jumps that manifest quickly. Either way, if your app has a memory leak, sooner or later it will cause problems. The source of and solution to PHP memory leaks aren’t always obvious, so you may need to try a few strategies before you eliminate the problem.

Thread Thread
 
xwero profile image
david duymelinck

To mitigate the vulnerabilities just update the php version, fixed.

I know the most website of the 70 percent use wordpress. I'm not happy about it, but i can't shake the feeling that with all those developers that are using "bad" code and bad php versions. There are enough bright minds that steer them in the right direction.

It is not a surprise go has no vulnerabilities, it doesn't move forward as much as other languages.

I didn't say memory leaks didn't happen, i said they are rare because a php app is a single request thing.

Lets just agree to disagree. I think we provided enough food of thought for the people who read this thread. I understand your point of view, and i think you understand mine but it's not going to be solved here :)

Thread Thread
 
valeriavg profile image
Valeria • Edited on

I'm sorry, I've removed the vulnerabilities links from my comment as it was referencing the wrong page relating Go.
Go does have almost the same amount and level of vulnerabilities reported this year as PHP.

Please note, that if you have already mastered PHP, know how to avoid common mistakes, how to upgrade all the parts of the toolchain and your existing project goes by just fine in PHP - keep using it, it seems like you've found a great fit.

But PHP path will not be easy on a beginner developer, as the only way to learn all of the above is through a lot of painful mistakes, that modern languages like Go would not let you make.

And yes, every time a developer would seek an advice regarding PHP development, he would get comments from one of these horrible people like me, that would try really hard to sheer him away from making yet another horrible wordpress website.
Peace!:-)

Thread Thread
 
xwero profile image
david duymelinck

You are not a horrible person, you are great!

It is good to provide another view on the code/language someone is using.

A horrible person is someone that just repeats the same arguments over and over again, until it becomes absurd.

I had be on my best game for this discussion, and you made me better. I thank you for that!

Collapse
 
andersbjorkland profile image
Anders Björkland

Welcome to the PHP experience! I got XAMPP too when I started out. I don't know how similar to Python you will find PHP, but it's a good language for building websites or Web applications. Hope you learn a lot, and can share your thoughts on it.

Collapse
 
vinic profile image
Vinicius Ithalo

Thank you!
I started coding this morning and must say that it really reminds me of Python but with its own personality. I'm still having some issues with things such as echo not using parenthesis and variables using '$' before their name, but it isn't anything that strange.
I'm currently looking into how PHP handles data types and Operators.

Collapse
 
andersbjorkland profile image
Anders Björkland

Yeah, I thought $ made the code look ugly at first but I'm so used to it now that I don't mind if at all. And yeah, echo as a language construct tripped me up too. It kind of shows the roots that PHP has as a language used as a templating and logic solution from way back. I don't do echo as much anymore since using a dedicated templating engine (Twig) that can render my pages.

Collapse
 
xwero profile image
david duymelinck

I suggest wamp if you want to install the php environment on windows. The main reason is that wamp allows you to add new php versions, but also new database and webserver versions, as an add-on package. With xampp you have to select the php version for the whole package.

If you want to get into containerized development give lando a try. docs.lando.dev/guides/setup-lando-....
Lando is basically a collection of templates to make it easier to create a docker setup.

Collapse
 
vinic profile image
Vinicius Ithalo

I'll take a better look into it, thank you for the suggestion, but for now I'll be using XAMPP, thoses options and addons probably won't be used until I get a better knowledge on the language. Thank you anyway.

Collapse
 
dendihandian profile image
Dendi Handian • Edited on

Once you done with Xampp, I suggest you to move into Laragon or Wamp, because storing projects in htdocs folder is just horrible.

Collapse
 
xwero profile image
david duymelinck

Why is that so horrible? In the webserver configuration you specify the directory that servers the url. You can serve a subdirectory on an other url if you want.
Go crazy and use as many sublevels if you want. I don't recommend it but there aren't any side effects. The only way that can happen is that the application code uses the same directories, but that is not a xampp problem.

Collapse
 
dendihandian profile image
Dendi Handian

it just (in my experience) many beginner in PHP that uses XAMPP doesn't know how to virtualhost their project as the project itself will use baseurl & routing in production.

Thread Thread
 
xwero profile image
david duymelinck

Xampp, and wamp, provides a page to create virtual hosts. So you don't need to know how to setup virtualhosts if you don't want to.

Thread Thread
 
xwero profile image
david duymelinck

Sorry i'm wrong, i just installed xampp to be sure.

It is only wamp that provides you with a page to create virtual hosts.

Thread Thread
 
dendihandian profile image
Dendi Handian • Edited on

horrible, right?

The beginner just rely on accessing project per nested folder in the url.

Collapse
 
vinic profile image
Vinicius Ithalo

Sure, people told me Xampp is good start but isn't really good for the future, so I'll take a further look into it. Thank you!

Collapse
 
dendihandian profile image
Dendi Handian • Edited on

If you're Windows machine and need reference about Laragon, you can see my posts about it dev.to/dendihandian/series/13731

Collapse
 
tramdhani profile image
Tri Ramdhani • Edited on

greats bro.

Build Anything...


Use any Linode offering to create something for the DEV x Linode Hackathon 2022. A variety of prizes are up for grabs, inculding $1,000 USD. 👀

Join the Hackathon <-