Two or fewer method/function arguments still ideal
What would you say, is the recommendation to give a method or function as few - in the best case two or fewer - arguments as possible still up to date?
I can understand that it is generally always better to use as few arguments as possible. However, this is often not feasible in practice.
I can also understand that before PHP 8, before named arguments existed, it was just ugly to pre-fill unused arguments.
See the following example function:
function font(string $file, string $color = '#000000',int $size = 12, float $lineHeight = 1, int $rotation = 0)
{
//
}
All arguments had to be filled before PHP 8 in order to create a default font with 90 degree rotation in the example.
// before PHP 8
$font = font('Example.ttf', '#000000', 12, 1, 90);
With PHP 8 there are fortunately named arguments:
// after PHP 8
$font = font('Example.ttf', rotation: 90);
This of course improves readability immensely. For this reason, I would say that there is not necessarily a reason to follow this recommendation. Of course, it still makes sense to split the arguments into higher-level objects if applicable. But not at all costs.
As long as there are only 1 or 2 without a default value, readability should still be guaranteed with named arguments. What do you think?
https://redd.it/1kpi29s
@r_php
What would you say, is the recommendation to give a method or function as few - in the best case two or fewer - arguments as possible still up to date?
I can understand that it is generally always better to use as few arguments as possible. However, this is often not feasible in practice.
I can also understand that before PHP 8, before named arguments existed, it was just ugly to pre-fill unused arguments.
See the following example function:
function font(string $file, string $color = '#000000',int $size = 12, float $lineHeight = 1, int $rotation = 0)
{
//
}
All arguments had to be filled before PHP 8 in order to create a default font with 90 degree rotation in the example.
// before PHP 8
$font = font('Example.ttf', '#000000', 12, 1, 90);
With PHP 8 there are fortunately named arguments:
// after PHP 8
$font = font('Example.ttf', rotation: 90);
This of course improves readability immensely. For this reason, I would say that there is not necessarily a reason to follow this recommendation. Of course, it still makes sense to split the arguments into higher-level objects if applicable. But not at all costs.
As long as there are only 1 or 2 without a default value, readability should still be guaranteed with named arguments. What do you think?
https://redd.it/1kpi29s
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Introspect for Laravel - Query your codebase like a database with an Eloquent-like API
https://redd.it/1kpoz7z
@r_php
https://redd.it/1kpoz7z
@r_php
The Laralist #58: Pipe operator v3 ➡️, Big improvements to Laravel Echo ⚡, Arr typed helpers 💡, FrankenPHP Is Now Officially Supported by The PHP Foundation 🧟, How Cursor Indexes Codebases Fast 🗂️
https://thelaralist.com/archive/9eef9045-6ba5-4dc4-a9a3-7280973add48
https://redd.it/1kpq25r
@r_php
https://thelaralist.com/archive/9eef9045-6ba5-4dc4-a9a3-7280973add48
https://redd.it/1kpq25r
@r_php
Thelaralist
RFC: Pipe operator v3 ➡️, Big improvements to Laravel Echo ⚡, Arr typed helpers 💡, FrankenPHP Is Now Officially Supported by …
The PHP RFC introduces a "pipe" operator `|>`, facilitating function chaining by passing the left-side value as the first parameter to a single-parameter callable on the right.
Voting so far is favorable, so the proposal will likely be accepted.
Voting so far is favorable, so the proposal will likely be accepted.
Weekly /r/Laravel Help Thread
Ask your Laravel help questions here. To improve your chances of getting an answer from the community, here are some tips:
What steps have you taken so far?
What have you tried from the documentation?
Did you provide any error messages you are getting?
Are you able to provide instructions to replicate the issue?
Did you provide a code example?
Please don't post a screenshot of your code. Use the code block in the Reddit text editor and ensure it's formatted correctly.
For more immediate support, you can ask in the official Laravel Discord.
Thanks and welcome to the r/Laravel community!
https://redd.it/1kpoq5b
@r_php
Ask your Laravel help questions here. To improve your chances of getting an answer from the community, here are some tips:
What steps have you taken so far?
What have you tried from the documentation?
Did you provide any error messages you are getting?
Are you able to provide instructions to replicate the issue?
Did you provide a code example?
Please don't post a screenshot of your code. Use the code block in the Reddit text editor and ensure it's formatted correctly.
For more immediate support, you can ask in the official Laravel Discord.
Thanks and welcome to the r/Laravel community!
https://redd.it/1kpoq5b
@r_php
Laravel
Installation - Laravel 12.x - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation — freeing you to create without sweating the small things.
Weekly Ask Anything Thread
Feel free to ask any questions you think may not warrant a post. Asking for help here is also fine.
https://redd.it/1kq1t0a
@r_php
Feel free to ask any questions you think may not warrant a post. Asking for help here is also fine.
https://redd.it/1kq1t0a
@r_php
Reddit
From the symfony community on Reddit
Explore this post and more from the symfony community
Weekly help thread
Hey there!
This subreddit isn't meant for help threads, though there's one exception to the rule: in this thread you can ask anything you want PHP related, someone will probably be able to help you out!
https://redd.it/1kq4h8w
@r_php
Hey there!
This subreddit isn't meant for help threads, though there's one exception to the rule: in this thread you can ask anything you want PHP related, someone will probably be able to help you out!
https://redd.it/1kq4h8w
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Who's hiring/looking
This is a bi-monthly thread aimed to connect PHP companies and developers who are hiring or looking for a job.
Rules
No recruiters
Don't share any personal info like email addresses or phone numbers in this thread. Contact each other via DM to get in touch
If you're hiring: don't just link to an external website, take the time to describe what you're looking for in the thread.
If you're looking: feel free to share your portfolio, GitHub, … as well. Keep into account the personal information rule, so don't just share your CV and be done with it.
https://redd.it/1kq67pi
@r_php
This is a bi-monthly thread aimed to connect PHP companies and developers who are hiring or looking for a job.
Rules
No recruiters
Don't share any personal info like email addresses or phone numbers in this thread. Contact each other via DM to get in touch
If you're hiring: don't just link to an external website, take the time to describe what you're looking for in the thread.
If you're looking: feel free to share your portfolio, GitHub, … as well. Keep into account the personal information rule, so don't just share your CV and be done with it.
https://redd.it/1kq67pi
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
New in Symfony 7.3: Yaml Improvements
https://symfony.com/blog/new-in-symfony-7-3-yaml-improvements?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1kq70bm
@r_php
https://symfony.com/blog/new-in-symfony-7-3-yaml-improvements?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1kq70bm
@r_php
Symfony
New in Symfony 7.3: Yaml Improvements (Symfony Blog)
Symfony 7.3 adds YAML flags to force quoted strings, compact nested maps, and dump empty entries.
Do not call toArray() to get all items from a Laravel Collection
https://spatie.be/blog/do-not-call-toarray-to-get-all-items-from-a-laravel-collection
https://redd.it/1kq5rxc
@r_php
https://spatie.be/blog/do-not-call-toarray-to-get-all-items-from-a-laravel-collection
https://redd.it/1kq5rxc
@r_php
spatie.be
Do not call toArray() to get all items from a Laravel Collection
Laravel's toArray collection method might not return what you might expect.
Symfony UX CVE-2025-47946: Unsanitized HTML attribute injection via ComponentAttributes
https://symfony.com/blog/symfony-ux-cve-2025-47946-unsanitized-html-attribute-injection-via-componentattributes?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1kqb2ls
@r_php
https://symfony.com/blog/symfony-ux-cve-2025-47946-unsanitized-html-attribute-injection-via-componentattributes?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1kqb2ls
@r_php
Symfony
Symfony UX CVE-2025-47946: Unsanitized HTML attribute injection via ComponentAttributes (Symfony Blog)
PHP on macos
Hi guys,
I was curious in what way you have PHP running locally. Currently using XAMPP but got a new macbook and wanted to a clean proper install.
Its for a custom PHP framework.
What would you recommend and why?
https://redd.it/1kqauqj
@r_php
Hi guys,
I was curious in what way you have PHP running locally. Currently using XAMPP but got a new macbook and wanted to a clean proper install.
Its for a custom PHP framework.
What would you recommend and why?
https://redd.it/1kqauqj
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Moving application logic out of livewire components to service classes. Used service classes to delete records.
Hello All,
I have posted here before about the project I have been working on for some time and have got some valuable feedback suggestions from you all.
I had got suggestion here to move the application/business logic from livewire components to service classes. I followed the pattern, and now have implemented delete functionality for most of the records using service classes.
As a whole, moving the application/business logic from livewire component to service classes feels much more cleaner than before. Having business logic in a service classes has given more freedom to call these services from any controller or livewire components.
Here is the github repo.
https://github.com/oitcode/samarium
More work/code is required to move most of the application logic from livewire components to service classes, but for now I have implemented deletion of records at least.
Worked some time on this, so sharing here, also thanks to all who suggested this change.
Thanks.
https://redd.it/1kqfdha
@r_php
Hello All,
I have posted here before about the project I have been working on for some time and have got some valuable feedback suggestions from you all.
I had got suggestion here to move the application/business logic from livewire components to service classes. I followed the pattern, and now have implemented delete functionality for most of the records using service classes.
As a whole, moving the application/business logic from livewire component to service classes feels much more cleaner than before. Having business logic in a service classes has given more freedom to call these services from any controller or livewire components.
Here is the github repo.
https://github.com/oitcode/samarium
More work/code is required to move most of the application logic from livewire components to service classes, but for now I have implemented deletion of records at least.
Worked some time on this, so sharing here, also thanks to all who suggested this change.
Thanks.
https://redd.it/1kqfdha
@r_php
GitHub
GitHub - shyamsitaula/samarium: Open-source business management system with ERP, POS, invoicing, and CMS features. Laravel-based…
Open-source business management system with ERP, POS, invoicing, and CMS features. Laravel-based, Docker-ready. Still in active development. - shyamsitaula/samarium
Frankenstein Migration: Mojavi to Symfony
I have a web application, that I currently maintain, that is a frankenstein of beast. As far as I can tell there are two php frameworks in this project, Mojavi 2.0 and Symfony 4.4, and I need to migrate it to one. It was originally built on Mojavi and then at some point someone added Symfony 4.4 but never fully migrated it.
I can't find any documentation on Mojavi. The only info I can get is from ChatGPT...and that was only helpful in understanding the structure. I want to do a phased rewrite to 6.4 or 7 but my boss is against it and thinks updating to 4.4 should be easy.
If anyone has experience with this kind of migration, can you help. With either how to refactor the code in Mojavi to Symfony 4 or convincing my boss to the rewrite.
https://redd.it/1kqhprb
@r_php
I have a web application, that I currently maintain, that is a frankenstein of beast. As far as I can tell there are two php frameworks in this project, Mojavi 2.0 and Symfony 4.4, and I need to migrate it to one. It was originally built on Mojavi and then at some point someone added Symfony 4.4 but never fully migrated it.
I can't find any documentation on Mojavi. The only info I can get is from ChatGPT...and that was only helpful in understanding the structure. I want to do a phased rewrite to 6.4 or 7 but my boss is against it and thinks updating to 4.4 should be easy.
If anyone has experience with this kind of migration, can you help. With either how to refactor the code in Mojavi to Symfony 4 or convincing my boss to the rewrite.
https://redd.it/1kqhprb
@r_php
Reddit
From the symfony community on Reddit
Explore this post and more from the symfony community
My 10-minute overview of the upcoming pipe operator 🤩
https://www.youtube.com/watch?v=UG_yb_WOutE
https://redd.it/1kqy4dn
@r_php
https://www.youtube.com/watch?v=UG_yb_WOutE
https://redd.it/1kqy4dn
@r_php
YouTube
An overview of PHP 8.5's pipe operator
PHP 8.5 will introduce a new pipe operator, let's take a look at how it works!
#php
#php
New in Symfony 7.3: JsonStreamer Component
https://symfony.com/blog/new-in-symfony-7-3-jsonstreamer-component?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1kr07ij
@r_php
https://symfony.com/blog/new-in-symfony-7-3-jsonstreamer-component?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1kr07ij
@r_php
Symfony
New in Symfony 7.3: JsonStreamer Component (Symfony Blog)
In Symfony 7.3, the new JsonStreamer component provides a high-performance, low-memory solution for encoding and decoding JSON at scale.
Is it safe to use emulated prepared statements in Laravel?
Hi everyone,
I’m building a DBA assistant. One challenge we’ve encountered is prepared statements in MySQL and MariaDB. They don’t leave much for analysis after they’re executed. We've sent this problem to MariaDB core developers.
Since Laravel uses PDO with prepared statements by default, it makes profiling harder. But there’s an option to enable “emulated” prepared statements in PDO. When enabled, queries are sent as raw SQL, which is easier to log and analyze.
So I’m wondering:
Would it be safe to enable emulated prepared statements in Laravel - at least in dev or staging - to get better query insights?
Curious to hear your thoughts.
https://redd.it/1kr08bs
@r_php
Hi everyone,
I’m building a DBA assistant. One challenge we’ve encountered is prepared statements in MySQL and MariaDB. They don’t leave much for analysis after they’re executed. We've sent this problem to MariaDB core developers.
Since Laravel uses PDO with prepared statements by default, it makes profiling harder. But there’s an option to enable “emulated” prepared statements in PDO. When enabled, queries are sent as raw SQL, which is easier to log and analyze.
So I’m wondering:
Would it be safe to enable emulated prepared statements in Laravel - at least in dev or staging - to get better query insights?
Curious to hear your thoughts.
https://redd.it/1kr08bs
@r_php
Reddit
From the laravel community on Reddit
Explore this post and more from the laravel community
[FrankenPHP] Managing Laravel Queues Efficiently With FrankenPHP, Redis and Docker
https://blog.danstorm.dev/blog/managing-laravel-queues-efficiently-with-redis-frankenphp-and-docker/
https://redd.it/1kr3dme
@r_php
https://blog.danstorm.dev/blog/managing-laravel-queues-efficiently-with-redis-frankenphp-and-docker/
https://redd.it/1kr3dme
@r_php
blog.danstorm.dev
Managing Laravel Queues Efficiently With FrankenPHP, Redis and Docker
Introduction TL;DR: Learn how to manage Laravel queues using Redis, Docker, and FrankenPHP. This guide walks through setting up a queue worker, dispatching jobs, and integrating Laravel Horizon — all within a Dockerized environment.
Continuing from the previous…
Continuing from the previous…
Accessing $this when calling a static method on a instance
In PHP, you can call a static method of a class on an instance, as if it was non-static:
class Say
{
public static function hello()
{
return 'Hello';
}
}
echo Say::hello();
// Output: Hello
$say = new Say();
echo $say->hello();
// Output: Hello
If you try to access
>Fatal error: Uncaught Error: Using $this when not in object context
I was thinking that using
class Say
{
public string $name;
public static function hello()
{
if (isset($this)) {
return 'Hello ' . $this->name;
}
return 'Hello';
}
}
echo Say::hello();
// Output: Hello
$say = new Say();
$say->name = 'Jérôme';
echo $say->hello();
// Output: Hello
This doesn't work!
The only way to have a method name with a distinct behavior for both static and instance call is to define the magic
class Say
{
public string $name;
public function call(string $method, array $args)
{
if ($method === 'hello') {
return 'Hello ' . $this->name;
}
throw new \LogicException('Method does not exist');
}
public static function callStatic(string $method, array $args)
{
if ($method === 'hello') {
return 'Hello';
}
throw new \LogicException('Method does not exist');
}
}
echo Say::hello();
// Output: Hello
$say = new Say();
$say->name = 'Jérôme';
echo $say->hello();
// Output: Hello Jérôme
Now that you know that, I hope you will NOT use it.
https://redd.it/1kr9kh3
@r_php
In PHP, you can call a static method of a class on an instance, as if it was non-static:
class Say
{
public static function hello()
{
return 'Hello';
}
}
echo Say::hello();
// Output: Hello
$say = new Say();
echo $say->hello();
// Output: Hello
If you try to access
$this from the static method, you get the following error:>Fatal error: Uncaught Error: Using $this when not in object context
I was thinking that using
isset($this) I could detect if the call was made on an instance or statically, and have a distinct behavior.class Say
{
public string $name;
public static function hello()
{
if (isset($this)) {
return 'Hello ' . $this->name;
}
return 'Hello';
}
}
echo Say::hello();
// Output: Hello
$say = new Say();
$say->name = 'Jérôme';
echo $say->hello();
// Output: Hello
This doesn't work!
The only way to have a method name with a distinct behavior for both static and instance call is to define the magic
__call and __callStatic methods.class Say
{
public string $name;
public function call(string $method, array $args)
{
if ($method === 'hello') {
return 'Hello ' . $this->name;
}
throw new \LogicException('Method does not exist');
}
public static function callStatic(string $method, array $args)
{
if ($method === 'hello') {
return 'Hello';
}
throw new \LogicException('Method does not exist');
}
}
echo Say::hello();
// Output: Hello
$say = new Say();
$say->name = 'Jérôme';
echo $say->hello();
// Output: Hello Jérôme
Now that you know that, I hope you will NOT use it.
https://redd.it/1kr9kh3
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Meract: A PHP MVC Framework with Built-in Frontend Integration (Morph) – Looking for Feedback
I’ve been working on Meract, an MVC framework for PHP that bridges backend and frontend seamlessly. It’s designed for developers who want an all-in-one solution with minimal setup. Here’s why it might interest you:
1. Morph: Integrated Frontend Framework
2. Laravel-like Syntax
1. Familiar routing, models, and migrations:
3. CLI Powerhouse (
4. Auth & Storage Out of the Box
5. Why Another Framework?
1. Unifies backend and frontend (Morph eliminates the JS build step for simple apps).
2. Is lightweight but extensible (e.g., swap Storage drivers for Redis).
3. Keeps PHP’s simplicity (no Webpack/config hell).
6. Is It Production-Ready?
1. Current state: Beta (The entire framework needs testing, and Morph, in particular, requires architectural improvements).
2. Github: https://github.com/meract/meract
https://redd.it/1krbhhh
@r_php
I’ve been working on Meract, an MVC framework for PHP that bridges backend and frontend seamlessly. It’s designed for developers who want an all-in-one solution with minimal setup. Here’s why it might interest you:
1. Morph: Integrated Frontend Framework
2. Laravel-like Syntax
1. Familiar routing, models, and migrations:
Route::get('/post/{id}', [PostController::class, 'show']); 3. CLI Powerhouse (
mrst)4. Auth & Storage Out of the Box
5. Why Another Framework?
1. Unifies backend and frontend (Morph eliminates the JS build step for simple apps).
2. Is lightweight but extensible (e.g., swap Storage drivers for Redis).
3. Keeps PHP’s simplicity (no Webpack/config hell).
6. Is It Production-Ready?
1. Current state: Beta (The entire framework needs testing, and Morph, in particular, requires architectural improvements).
2. Github: https://github.com/meract/meract
https://redd.it/1krbhhh
@r_php
GitHub
GitHub - meract/meract
Contribute to meract/meract development by creating an account on GitHub.