I didn't use PHP since ver 4-5. This looks like a different language. Even so I hope I won't have to use it again.
PHP 8: Before and After
81–90 of 346 posts
Re: PHP 8: Before and After
#82Earlier quoted context omitted.
> It's becoming kind of an Enterprise language It tried for decades to be one with Doctrine, Symonfy and co, trying to copy the worst of Java EE with every single possible design pattern implemented in these frameworks, XML configuration files and co... The problem is no generics, no private packages makes PHP OO a horrible mess compared to Java (or C#).
It's a different culture. They go around the problems differently. Also the way the write programs seems simpler and leaner (composer in mind)... probably not ultra safe but a good enough ratio I guess.
No it's not a different culture, they(enterprise Java and enterprise PHP) both try to force some IoC container everywhere, except PHP is an interpreted language, it doesn't need a IoC container with with XML/YAML configuration files cause there is no long and costly compilation step to begin with...
Re: PHP 8: Before and After
#83Can 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…
Adding tests for an app with no documentation requires a lot of effort.
Re: PHP 8: Before and After
#84So php tries so hard to be Java. Well, just stick with Spring and get the job done professionally. Learning PHP these days is a waste of time.
What language _isn't_ trying to be Java these days? What the old jargon file described as "bondage and discipline lanugage" applies to all major programming environments now, as Java proved that you can actually commodify programmers quite well and both old-school enterprises and the SV juggernaut need their harvest. C#, TypeScript, Go, PHP -- they all converge on the same methods, tools and workflows. Tech choice th…
At first we had guilds and craftsmen. We could only produce a few things, their quality was quite low and the products were expensive. This was one of the reasons quality of life was quite bad, actually.
Then we created the assembly line, standardized parts, mass production. Life sucked for the assembly line worker, but everyone else benefited. From a certain point of view even the assembly line worker benefited.
Hand crafting doesn't scale. 1 brilliant coder with in the Lisp Ivory Tower won't ever be able to reproduced the output of 100 decent covers in the Java Middleware Shop. It stands to reason, those decent coders can use their brains and time to test more, implement more kinds of features, talk to customers, colleagues, bosses, maybe even promote their product and do all sorts of things human beings do when they want something (coding is only a minor part of creating a successful product).
Two heads are better than one. And 100 heads that are not at loggerheads are better than two.
Re: PHP 8: Before and After
#85Can 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…
As others said, vscode with php extensions works quite well (you do need a local php install for intellisense to work iirc?)
As for migrating. I wouldn't aim for 8, that's a hell of a jump to make from 4/5 and just getting to 7.x would give you a few years of breathing room https://www.php.net/supported-versions.php .
First goal, get it working on 5.6 without any deprecation errors or notices, that's a good basis for a "legacy" codebase to be on.
From there, the hop to 7.x is mostly changing any mysql_* calls, avoiding the short tags (use `https://www.php.net/manual/en/migration70.php (other version notes available from the menu on that page).
As for tooling, Rector, phpstan and Psalm might be helpful, but might be more trouble than their worth if you've only dipped your toe into PHP development. Rector can do automated refactoring with some code (helpful for the mysql_* function removal/replacement with mysqli_* for instance). phpstan and psalm are static analysis tools that can help find problems or issues with the code.
Final comment, make sure this is in version control so you can track any changes made and have known working versions.
Re: PHP 8: Before and After
#86I'm glad you can now write: public static function new(): static { return new static(); } It really brings the point across it's static.
I know you're trolling, but FYI the `static` before function has nothing to do with the `static` return type. Like other programming languages the term `static` is used to denote two things.
It's not an excuse for slacking on language design.
Re: PHP 8: Before and After
#87Earlier quoted context omitted.
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…
All good advice for the average PHP developer, but I think it is overkill for someone that is starting with PHP just to keep alive a very old app. Adding tests for an app with no documentation requires a lot of effort.
Re: PHP 8: Before and After
#88Earlier quoted context omitted.
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.
Re: PHP 8: Before and After
#89I'm not up to date on php code, but can't the first example be done using reflection? For example a SubscriberBase class which: lists all of its "on*" methods, checks if there's only one parameter, gets its type via https://www.php.net/manual/en/reflectionparameter.gettype.ph... and registers the method to receive events of that type. From the docs it looks like it's possible in php7 and doesn't need explicit text ma…
I'd need to check if this is still the case in PHP, but Reflection was orders of magnitude slower just a few short years go for cases such as ReflectionClass->methodExists() vs method_exists()
Re: PHP 8: Before and After
#90Earlier quoted context omitted.
This is such a shallow elitist comment. A lot of the common criticisms levied at PHP have been corrected years ago, and PHP is responsible for hundreds of billions of dollars of turnover globally. Of the top 10 websites in the world, PHP is partially or wholly powering more than half of them. Wikipedia, Wordpress, online retail. I have personally created 6 figures of value because I could quickly dump some PHP script…
How can you call this elitism? Nobody forces you to learn PHP, you can learn any of the many other open source existing languages. There's no gatekeeping preventing you from learning languages other than PHP. I'm just calling it for what it is: a broken tool. I'm suggesting we let go of this broken tool and focus on tools that already work great, instead of wasting millions of human work hours on sub-par coding. Sure…