Live data from Hacker News

PHP 8: Before and After

stitcher.io

71–80 of 346 posts

Re: PHP 8: Before and After

#71

Can a fellow geek knowledgeable in PHP gives me a few pointers? I have inherited a 12 year old PHP app written by 2 interns. The code was written with Notepad++ (no IDE), no comments except when they copy pasted something from the internet, most variables are single letter and it's the biggest spaghetti bowl I have ever seen. To add insult to injury I have no experience with PHP (apart from peeking at this code to fi…

> Is there a way for me to have an IDE with a kind of "compiler" that would help me convert this to PHP 8 so I can migrate it on a more recent VM? Of course there's 0 budget for this.

There is your problem. If it's runs on PHP5 (<?php phpinfo(); // in a php page), it might run without hurdle on more recent versions of PHP... or not, but PHP8 isn't a different language, they just added some stuff on top of PHP5. C extensions might break though, because yes, PHP relies heavily on them as the language is too slow to do anything meaningful like writing a database driver.

Re: PHP 8: Before and After

#72

Can a fellow geek knowledgeable in PHP gives me a few pointers? I have inherited a 12 year old PHP app written by 2 interns. The code was written with Notepad++ (no IDE), no comments except when they copy pasted something from the internet, most variables are single letter and it's the biggest spaghetti bowl I have ever seen. To add insult to injury I have no experience with PHP (apart from peeking at this code to fi…

IDE: Visual Studio Code with the PHP extensions, free. Compiler: you are looking in the wrong direction, PHP is interpreted. There were some compilers, but it's not what you need. Converting to PPHP 8: do you need that? what are you trying to achieve? You can keep the app another year or so it it is working, don't fix what is not broken. There is no way to convert to 8, you need to rewrite it, PHP become more object…

I was able to convert a PHP 5.4 app to 7.1 but after that there are too many backwards incompatible changes to be easy to fix. Even the upgrade to 7.1 took a few days of tweaks to the code.

In my case the upgrade was demanded by security because the latest PHP5 release is no longer maintained.

For an internal app you're much better off just leaving it on PHP 5. Maybe add an op-cache for performance.

Re: PHP 8: Before and After

#73

Can a fellow geek knowledgeable in PHP gives me a few pointers? I have inherited a 12 year old PHP app written by 2 interns. The code was written with Notepad++ (no IDE), no comments except when they copy pasted something from the internet, most variables are single letter and it's the biggest spaghetti bowl I have ever seen. To add insult to injury I have no experience with PHP (apart from peeking at this code to fi…

Roughly in the order you should do it. Hopefully it's at least PHP 5.3 code:

1. Definitely get a PHP IDE: https://www.jetbrains.com/phpstorm/

2. Get a step debugger and hook it in: https://xdebug.org/

3. Fix the code style: https://github.com/FriendsOfPHP/PHP-CS-Fixer

4. Run the code through some static analysis tools https://phpstan.org/ https://psalm.dev/

5. Upgrade the code with an AST fixer (might help you update to newer PHP version): https://github.com/rectorphp/rector

6. Add tests to it: https://phpunit.de/

7. Run mutation tests: https://infection.github.io/

The "0 budget" is rough, though.

Re: PHP 8: Before and After

#74

Earlier quoted context omitted.

> You can’t build websites with Java The (popular) horrors that are Symfony, Laravel, Doctrine and co were all inspired by Java Web frameworks and ORM.

Spring was first MVC framework, but Laravel in PHP and Django in Python were inspired by Ruby on Rails.

Laravel was inspired by ASP MVC, which itself took inspiration from Spring, not Ruby on Rails.

Re: PHP 8: Before and After

#75

Can a fellow geek knowledgeable in PHP gives me a few pointers? I have inherited a 12 year old PHP app written by 2 interns. The code was written with Notepad++ (no IDE), no comments except when they copy pasted something from the internet, most variables are single letter and it's the biggest spaghetti bowl I have ever seen. To add insult to injury I have no experience with PHP (apart from peeking at this code to fi…

[deleted]

Re: PHP 8: Before and After

#76

I'm glad you can now write: public static function new(): static { return new static(); } It really brings the point across it's static.

Why didnt they use the term singleton or object?

What would they use it for? The first 'static' means the method is a part of the class rather than the instances of that class. The second and third 'static' indicate late static binding, meaning they refer to the class being called, rather than the class defining this method.

Re: PHP 8: Before and After

#77

Can a fellow geek knowledgeable in PHP gives me a few pointers? I have inherited a 12 year old PHP app written by 2 interns. The code was written with Notepad++ (no IDE), no comments except when they copy pasted something from the internet, most variables are single letter and it's the biggest spaghetti bowl I have ever seen. To add insult to injury I have no experience with PHP (apart from peeking at this code to fi…

Getting a copy of PHPStorm will make things much easier, you can run Reformat code on PHP files and you can also do mass updates from code inspections.

Also worth checking out is a package called Rector (https://github.com/rectorphp/rector) which will automate a lot of this by scanning the codebase and providing diffs so you can upgrade safely.

Re: PHP 8: Before and After

#78
post #36

Earlier quoted context omitted.

Lately I see myself abusing (???) types more often than ever. Before, I'd feel comfortable returning an array of structured data from a function. Now, I'm creating Value Objects to ensure my data is both valid and correctly used elsewhere. Kinda feels nice to get intellisense working too and knowing that the things that I'm trying to do with that VO are valid

> Before, I'd feel comfortable returning an array of structured data from a function. Now, I'm creating Value Objects to ensure my data is both valid and correctly used elsewhere. Same. I've written some complicated ETL/data transform processes in PHP, and used arrays because the array_* functions are so useful for manipulation. But keeping track of what keys were available was a nightmare - especially coming back to…

PHPStan and Psalm support what they call "array shapes", basically you can treat the array keys as a type, similar to how TypeScript does it.

Re: PHP 8: Before and After

#79

Earlier quoted context omitted.

You can’t build websites with Java

Spring Boot and https://micronaut.io/ gets my job done. Thank you. Yes, I build web apps with Java so I don't have to waste my time with php. Life's too short. And I am old enough to remember the abomination Joomla was back in early 2000's and how horrible php was back then when my clients wanted to have their "sites" done in Joomla with custom plugins.

Spring Boot code is probably going to be less maintainable than PHP though. Added a new dependency? Congratulations, now your application behaves completely differently.
Post reply on HN