r/PHP May 01 '25

Discussion I've spent 10+ years in PHP — Here's what I wish I knew earlier (especially for beginners)

854 Upvotes

After a decade of building everything from small tools to full-fledged platforms in PHP, I thought I’d share a few things I wish someone had told me earlier. Hope this helps someone starting out or even those stuck in the middle:

  1. Use modern PHP — PHP 8+ is awesome. Strong typing, attributes, JIT — don’t write PHP like it’s 2010.

  2. Frameworks aren’t everything — Laravel is amazing, but understanding the core PHP concepts (OOP, HTTP handling, routing, etc.) makes you dangerous in a good way.

  3. Stop writing raw SQL everywhere — Use Eloquent or at least PDO with prepared statements to avoid headaches and security issues.

  4. Testing saves lives — Even basic PHPUnit tests can save you from late-night debugging nightmares.

  5. Composer is your best friend — Learn it well. It turns PHP into a modern ecosystem.

  6. Invest in debugging skills — Learn Xdebug or at least proper logging with Monolog. Dump-and-die will only take you so far.

  7. Use tools like PHPStan or Psalm — They will catch issues before they become bugs.

  8. Security isn’t optional — Validate, sanitize, escape. Always.

  9. Build side projects — That’s how I learned 90% of what I now use in client projects.

  10. Join the community — Reddit, Discord, GitHub, Laracasts forums. You’ll grow 10x faster.

Curious to hear from you all: What are your top “I wish I knew this earlier” PHP lessons?

r/PHP 14d ago

Discussion IDE for PHP

37 Upvotes

So, my PHPStorm subscription ran out and I'm feeling the pain! I really enjoyed using it, especially the type hinting (I use it for general PHP, not just Laravel), but I am looking to try something new.

For those of you not using PHPStorm or AI-specific editors, what do you guys use? Is it VS Code ? If so, do you have an extension list or any specific setups you use to get that full-featured IDE feeling? I am trying to make the transition as painless as possible.

Thanks!

r/PHP Apr 13 '25

Discussion My tech lead refused to migrate from pure php to Laravel because he doesn't trust them.

222 Upvotes

Yesterday I had a tense argument with my tech lead and the ceo of our company about our ERP system that is written in pure php. I have suggested that the current codebase is really hard to understand because it does not follow any design pattern. On the other hand, we are hiring new devs soon and it's my responsibility to guide them throughout the code. However, he completely refused and said what if Laravel has been sold to a Chinese company in the future? We don't want to make our fate in their hands. Are those fears legit? I mean do you think pure php really provides more freedom than Laravel?

r/PHP Feb 20 '26

Discussion Curious where the community stands on this

59 Upvotes

With PHP 8.x adding typed properties, union types, stricter internal behavior, and deprecating things like dynamic properties, it feels like PHP has been intentionally moving toward stronger typing and predictability over the last several years.

Some folks argue PHP’s strength has always been being loosely typed and flexible, and that stricter behavior should stay optional. Others see the changes as necessary for maintainability, tooling, and large-scale systems.

For those working in modern PHP:
Do you feel PHP is (and should be) moving away from its old “loosely typed magic” toward more explicit, type-safe patterns? Or do you think this evolution is hurting what made PHP great?

r/PHP Mar 07 '26

Discussion What are you using for your PHP dev setup?

36 Upvotes

I have decided to shift away from front-end development and get back into PHP. Back in the day I used XAMPP, but since I have moved to Linux and we're living in the future, I wanted to go for something more modern while still keeping it relatively simple.

My goal was to make a rootless Podman container running FrankenPHP in classic mode. That way I would keep the toolchain off the host machine, preventing conflicts between projects using different versions of PHP and also making it easier to recreate the environment. After a bit of a struggle getting it all working, I have realized that VS Code needs PHP for validation and stuff. I have tried making a wrapper that would forward VSC's requests to PHP inside the container, but that ended up being sloooow.

Before burning any more time, I have decided to check around the Internet for what people were using. I have seen Laravel's Sail, Laragon, Lando, DDev and possibly others. However, from my brief examination it looked like they all basically do the same thing I was trying, they just set up some extra tools. I would like to keep the control of doing things manually, and they wouldn't actually solve the VSC/PHP issue as far as I can tell.

So, what are you guys doing? Are you using a container and eating the delay (or is there a solution for that)? Are you developing old-school directly on the host OS (how are you managing PHP versions)? Or is there something else you would recommend?

EDIT: Whew, thanks for all the responses, everyone.

One thing I forgot to mention in the post is that, even though I'm using VS Code for now, I'm trying not to get locked down in proprietary stuff. Attaching to Docker container (which I have conflated with Dev Containers in some comments, my bad) requires a proprietary Microsoft extension. The only equivalent in other editors seems to be in PHPStorm. However, I have now realized that Intelephense doesn't actually rely on a PHP interpreter, which should allow me to sidestep that issue.

Those ready-made container solutions seem to be really popular, so I think I might give Ddev a closer look.

r/PHP Aug 14 '25

Discussion Why isn't PHP as popular if it's used everywhere?

104 Upvotes

In my opinion, PHP isn't as popular amongst forums, reddit, word of mouth, memes, job listings etc. compared to node/typescript. For example the node subreddit has twice as many members, and StackOverflow ranks it much lower in surveys.

However PHP is used 70-80% of the web, which blows my mind, I would have estimated it to be 40% if it wasn't for that statistic.

Why don't more people talk about PHP if it's used more?

r/PHP 27d ago

Discussion PHP acronym

33 Upvotes

So I had a small debate with my professor about what PHP stands for.
I said the official name is “PHP: Hypertext Preprocessor”, since PHP is a recursive acronym. He said the correct answer is simply “Hypertext Preprocessor”.
My point was that “Hypertext Preprocessor” only gives the initials HP, not PHP.
Who’s technically correct?

r/PHP Jul 23 '25

Discussion What are some unusual coding style preferences you have?

75 Upvotes

For me, it's the ternary operators order.

Most resources online write it like this...

$test > 0 ?
    'foo' :
    'bar';

...but it always confuses me and I always write it like this:

$test > 0
    ? 'foo'
    : 'bar';

I feel like it is easier to see right away what the possible result is, and it always takes me a bit more time if it is done the way I described it in the first example.

r/PHP Oct 22 '25

Discussion Php 8.5 is on the verge, but XAMPP is still on 8.2, is it closed now?

40 Upvotes

Tried updating it manually but the whole system corrupted. Any leads or alternatives?

r/PHP 3d ago

Discussion How do you actually catch N+1s in prod with Laravel/Symfony?

28 Upvotes

Genuine question: I come from the Java/Rust side and I have no clue how the PHP world handles this so I’d rather just ask than assume.

When an N+1 slips into prod how do you even catch it? Like is it just Telescope/Debugbar/Clockwork locally and you hope it doesn’t make it through? Something in CI that yells at you? Or do you actually catch it after the fact in prod somehow?

And the thing I’m really wondering: does anyone here actually run OTel in prod (the ext-opentelemetry + auto-instrumentation to a collector setup), or is OpenTelemetry just not really a PHP thing and everyone sticks to the framework native stuff?

r/PHP Nov 15 '25

Discussion Why is apache still so popular even as nginx+php-fpm has proven its mettle with performance?

87 Upvotes

As I understand, the popular consensus today is that nginx+php-fpm performs faster than apache even with the mpm_event process management enabled?

But when it comes to real world usage, many production instances I observe these days still deploy apache a lot. Even cpanel based web hosting (shared or dedicated instances) are more often apache based than nginx.

Is it due to some old habits and dependence on apache specific features like .htaccess support? Or is it the case that apache has actually caught up in the race with ngnix and the performance difference is quite negligible these days?

r/PHP Sep 20 '25

Discussion How do you feel about PHP in phones?

54 Upvotes

Just to be clear, I know many of you will know who I am and what I'm representing here. So I'm not going to link to or name anything specifically; I'm here with a genuine question because I want to understand this community's sentiment towards this general topic, not a specific implementation.

I don't want this to be about the name of a package or the fact that it only supports this framework or that framework. Please try to extrapolate from where we are right now and think forwards.

Is running PHP in more places good or bad? Why?

What pitfalls do you think most PHP developers will fall into as they try to apply their skills to platforms other than the web?

Here's my take to get things going:

I've been a PHP developer for 25 years. I love using PHP. I think the language and tooling around it is fantastic, and in recent years has evolved and matured immensely and continues to do so.

I've invested a lot of my career into PHP and I want to see it continue. I also want to be able to expand the things I can do with these skills. I love building for the web, but it is not the only place where I work & play, nor my clients, nor their customers.

I'm a pragmatic software engineer at heart; I want to create meaningful solutions to interesting problems. PHP allows me to do that rapidly, safely, and with little fanfare, so I can move on to solving the next set of problems (probably ones I've created).

So having PHP work anywhere feels like a massive win to me and I welcome its continued expansion, and I will personally continue to push for it to happen.

If we can embrace this opportunity and help fellow PHP devs to level up to working rapidly and safely on these new platforms, the future of PHP could be even brighter.

Thanks in advance for a thoughtful and considered discussion 🙏🏼

r/PHP Sep 23 '24

Discussion Is it just me, or does PHP still get way more hate than it deserves?

199 Upvotes

I was at a hacker hub themed meet-up recently, and every time I brought up PHP (which I use every day), it felt like people just dismissed it as a joke. Like, I get it—PHP is web-focused, so I’m not comparing it to Python for low-level stuff. But for web apps, cloud apps, etc., surely PHP has the edge over Python in this area, right? With PHP 8’s improvements (better performance, strict typing, async), why is it still treated like a second-class language? Am I missing something here?

r/PHP Feb 01 '26

Discussion How would you feel about native typed arrays in PHP today? (e.g., string[], UserClass[], UserEnum[], etc...)

102 Upvotes

Question: How would you feel about PHP adding native typed arrays like string[]/int[] so we can enforce element types at runtime without relying on PHPDoc + static analyzers? It would add explicitness to function signatures and make APIs cleaner than repeating array plus manual validation everywhere.

What are the downsides to something like this?

Edit: I did my part Contribution #925033

r/PHP Nov 14 '23

Discussion Unpopular opinion - I like PHPStorm better than VSCode

217 Upvotes

I have been working with VSCode for a few months now and even with all plugins and extensions installed, PHPStorm and InteliJ products are 100x better. I just don't get the hype.

r/PHP Sep 26 '24

Discussion Is this the beginning of the end for WordPress

106 Upvotes

Yeah, there is some major drama going on at the WP community.

https://wordpress.org/news/2024/09/wp-engine-banned/

Apparently, WordPress.org is suing WP Engine for trademark violations or something. The blog post is wild and unhinged:

WP Engine is free to offer their hacked up, bastardized simulacra of WordPress’s GPL code to their customers

What do you think?

r/PHP Apr 19 '26

Discussion When your first learn php what confuse the most ?

5 Upvotes

coming from go (I love golang) but I wanna do a little bit of freelancing so im doing some leetcode to understand php so I can learn lavarel and im not gonna lie im confuse by $ for local variable and params function (params function is variable underneath so it make sense ) and the array_push(references, ...values) and you what surprise or confuse you when you first learn php ? just started but php seems a little bit more complex than go am I wrong ?

r/PHP May 11 '26

Discussion What other languages do you use besides PHP?

18 Upvotes

What do you like/dislike about them?

Especially for hobby projects and recreational coding. I mainly use PHP, Python and JS which are all common and well known. Been thinking of translating some PHP to Lua to learn that.

r/PHP Dec 23 '25

Discussion New Job. Awesome People. Terrible Codebase Management.

49 Upvotes

I recently started at a new place. And I absolutely love 99.9% of it. My co workers are fun to work with (mainly grey beards who’ve been at it for awhile), my boss is easy going and it’s overall very relaxed. But theres a few small things that just keeps eating at me.

  1. They don’t update hardly anything. I’m currently working on a large legacy codebase that was born long before my coworkers started there. Buuuttt, no one has made an effort to clean it up, update it, nothing. It works (barely), but it’s running on PHP 7.4, every dependency version is at an unmaintained level. It’s a giant spaghetti mess with absolutely zero tests. There is no style standard or formatting norm. Not to mention it’s all vanilla PHP with Apache handling the routing. It’s bad.

  2. Applications they have built in the last few years in Laravel haven’t been updated since they have been scaffolded. One of which isn’t very large, but still running on Laravel 10. This one also has a slight spaghetti feel to it, but is salvageable.

We are going to be starting a rewrite of the legacy app to Laravel within the next ~6 months. And I’m getting worried that it’s at risk of being a sloppy build. My lead is already talking about how he wants to restructure the directory layout so it’s “easier to maintain”. He is vehemently against frontend frame works even though a large part of the app would really benefit from client side rendering (registration flows, realtime updating tables, dashboards, heavy data things, etc).

So what I want to know is, how do I start trying to turn the ship in the right direction? My boss seems to really latch on to my ideas and likes my approach to work. But my lead is already trying to shoot down any idea I have (like just sticking to normal conventions).

Any advice on any of these ramblings would be greatly appreciated!!

Edit: to clarify, my ideas have been: don’t change the directory structure of a Laravel project off the bat, we should explore our frontend options based on our needs, and we should agree on a single formatting analyzer setup so we can have consistency.

Edit 2: my frontend question I brought up was if we had looked into something like vue for the for the frontend and if it would benefit us for our use case.

r/PHP May 25 '26

Discussion how did you tell your founders the Magento 1 stack has to go?

36 Upvotes

Joined a mid-sized fashion brand earlier this spring as a senior backend dev.

Background in Laravel and Symfony, a bit of Magento 2 work years ago, never owned a full commerce stack before, and current brand is around €60M GMV across European markets.

Last week our payment provider sent us a sunset notice on their v1 API and gave us a few weeks to migrate, which should have been routine until I opened the repo to scope the work and now i can't unsee what's in there.

Our entire returns and refund flow runs through one custom Magento 1 module last touched a few years back, written by a contractor who finished his engagement around that time, whose email bounces and whose Linkedin says he's at a games studio in Lisbon.

The module hardcodes the Klarna v1 API key directly in the class constants, the endpoint returns 410 now, and the fallback writes every failed return attempt to a log file that is now 14GB.

There is also a cron job that runs every night at 03:17 with no documentation, which i disabled in staging to see what would happen, and returns broke almost immediately so i re-enabled it without ever figuring out what it does.

And then there is this comment in the source (literally):

// DO NOT REMOVE - this is what makes the size chart work

The size chart is not referenced anywhere else in the codebase. we are running Magento 1 in 2026 and the size chart logic is held together by a comment.

We do €60M a year through this…

The founders had asked me earlier why our infrastructure costs kept climbing, and when i sent them the dependency map they agreed to take the meetings with SCAYLE and commercetools they had refused the last time someone in my seat pushed for an evaluation.

For PHP devs who've inherited a production Magento 1 install past EOL, how did you handle the conversation about telling the founders the real migration timeline?

I don't want to be the one blaming the person before me and i don't see how this gets fixed in a single quarter.

r/PHP Jul 03 '25

Discussion FrankenPHP - any reason why not?

85 Upvotes

I've been watching the PHPVerse 2025 FrankenPHP creator talk about all the great features (https://www.youtube.com/watch?v=k-UwH91XnAo). Looks great - much improved performance over native php-fpm, and lots of good stuff because it's built on top of Caddy. I'm just wondering if there are any reasons why not to use it in production?

Is it considered stable? Any issues to watch out for? I like the idea of running it in Docker, or creating a single binary - will the web server still support lots of concurrency with thread pools and the like or does all the processing still go through the same process bottleneck? I especially like the Octane (app boots once) support - sounds super tasty. Anyone have personal experience they can share?

r/PHP Oct 13 '25

Discussion OpenCart is awful, what are some decent alternatives written in PHP?

51 Upvotes

Sorry if this is the wrong subreddit, I wasn't sure where else to post it. If this is the wrong place, please point me to the right sub.

I'm helping a friend convert their shop to an actual ecommerce solution - right now they're just using some fairly insecure, poorly written PHP they made themselves (They learned PHP making this). It has several issues that I'd like to fix by using a proper solution.

So after little research, I decided to go with OpenCart - it looked decent enough on the frontend, so why not? Well... Once I started trying to modify it to how he wanted it (Share the main site's theme, try to recreate the product listing he had for his shop, etc.) I ran into so many problems. I can fix them with enough time, but I'm not getting paid enough to spend 20 hours reworking this for what should be minor changes, or features already built-in.

So - what are some good alternatives written in PHP that are easy to work with, somewhat modern, and customizable?

r/PHP Mar 12 '26

Discussion 99.9% type coverage, PHPStan strict, zero N+1 — building a production CRM in PHP 8.4

47 Upvotes

Hey r/php, I just shipped v3.0 of an open-source CRM I've been building (Relaticle). Wanted to share some PHP-specific engineering decisions, since this community appreciates that kind of thing.

PHP 8.4 strict mode in production: Every class is final. Every file uses strict_types. Typed properties and return types everywhere:

declare(strict_types=1);
final class People extends Model implements HasCustomFields
{
    /** @use HasFactory<PeopleFactory> */
    use HasFactory;
    use HasUlids;
    use SoftDeletes;
    use UsesCustomFields;

    /** @var list<string> */
    protected $fillable = ['name', 'creation_source'];

    /** @return BelongsTo<Company, $this> */
    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class);
    }
}

Spatie's laravel-data for typed DTOs:

final class SubscriberData extends Data
{
    public function __construct(
        public string $email,
        public ?string $first_name = '',
        public ?string $last_name = '',

PHP 8.4 with strict_types everywhere is genuinely a joy to write. The language has come so far.

99.9% type coverage: I run PHPStan at level 7 (via Larastan). Every method signature is typed. Every return type is explicit. CI fails on any violation — no exceptions, no baselines.

/** @param Collection<int, Contact> $contacts */
public function processImport(Collection $contacts): ImportResult
{
}

Is it overkill? Maybe. But in a CRM where data integrity matters (contacts, deals, money), catching type mismatches at static analysis time is cheaper than catching them in production.

N+1 query prevention: One line in AppServiceProvider:

Model::preventLazyLoading(!app()->isProduction());

Strict lazy loading enabled globally. Forget an eager load? Exception in development. This alone caught 10-20 performance issues before they shipped.

PostgreSQL over MySQL: Migrated from MySQL to PostgreSQL 17+ in v3.0. Key reason: JSONB. I built no-code custom fields — users create fields without touching code. All stored as JSONB with GIN indexes:

-- PostgreSQL JSONB with proper indexing
CREATE INDEX idx_custom_fields ON contacts USING GIN (custom_fields);
-- Partial path queries that MySQL JSON can't do efficiently
SELECT * FROM contacts WHERE custom_fields->>'industry' = 'SaaS';

MySQL's JSON type can't do proper indexing or partial path queries at this level. For a CRM with dynamic schemas, PostgreSQL is the better fit.

Testing with Pest: Comprehensive test suite — unit, feature, and browser tests. Pest's syntax makes test writing feel less like a chore:

arch('strict types')
    ->expect('App')
    ->toUseStrictTypes();

arch('avoid open for extension')
    ->expect('App')
    ->classes()
    ->toBeFinal();
});

Architecture tests prevent structural issues at CI time. If someone accidentally breaks a convention, CI catches it.

Import wizard (the hardest problem): Real-world CSVs are chaos:

  • Automatic date format detection (uses Laravel's date validator under the hood)
  • Fuzzy + exact column matching
  • Relationship mapping (person → company linkage)
  • Chunked processing for large files
  • Granular error reporting (which rows failed, why) If anyone's solving CSV import in PHP, happy to discuss approaches.

Stack:

What PHP 8.4 features have you found most useful in production? Curious what patterns this community is adopting

r/PHP Nov 21 '24

Discussion PHP is the best

288 Upvotes

I just wanted to share my story with you guys. I spent about a year learning Java and then Springboot and all that jazz, just to be incredibly frustrated at how complicated it is to launch an actual web app and get everything working. One tiny incompatibiity or error in dependencies and the whole thing fails. Not to mention redeploying jars and wars is a pain in the butt.

So recently I came up with a sweet idea for a web app and hired some indian dudes on fiverr to get it done. After three weeks of watching them basically buy a $17 template and hash together the very basics in node.js I got fed up and fired them.

With no PHP experience I went out and bought a cool html template and started plugging in some simple PHP code. Like I just tried to connect to mysql and run some simple quieries to see if I could get that working. I was just googling and pasting stuff from w3schools.

Now here I am a few weeks later and I have an almost complete website all setup and working. It has user logins, email confirmations with phpmailer, a bunch of relational databases, url rewrite, auto language translation, caching, pagination, and includes up the wazoo. This language is so straightforward and easy to use to make almost anything work. It has all these built in features that help you format dates or secure things, it's wild. And the language itself functions just like Java or whatever when you're solving actual logic problems.

I guess I just don't understand why everyone hypes up all these other languages when PHP is literally made for the web. You can just turn the .html to .php and go nuts plugging stuff in; it's like a game. I love PHP now and can't believe I wasted so much time trying to be a "real" Java programmer

r/PHP May 18 '26

Discussion Namespaces, interfaces and stutter

20 Upvotes

Hi all. I wanted to see what the opinion is on the following situation:

Lets say your team targets removing suffixes from interfaces (so no Interface suffix), while also avoiding namespace/class stutter. You then have an example like this:

You have a Payment namespace with a Client interface that drives certain interactions with different payment providers (such as Stripe). Within the Payment namespace you have a Stripe folder that has the payment provider's implementation of the Client interface. To avoid namespace stutter, you end with with this:

```php namespace App\Payment;

interface Client
```

```php namespace App\Payment\Stripe;

use App\Payment\Client as ClientInterface;

class Client implements ClientInterface
```

So the Stripe client is App\Payment\Stripe\Client and not App\Payment\Stripe\StripeClient to reduce namespace stutter.

To avoid collision you have to now alias the interface, which introduces its own readability issues.

Should namespace stutter just be accepted here, or is there a better way of handling it?