Introducing ‘godump’ – a Symfony/Laravel Inspired Pretty-Printer for Go Structs and Values.
https://redd.it/1kwvcgv
@r_php
https://redd.it/1kwvcgv
@r_php
Reddit
From the laravel community on Reddit: Introducing ‘godump’ – a Symfony/Laravel Inspired Pretty-Printer for Go Structs and Values.
Explore this post and more from the laravel community
What the best strategy to handle multiple possible different exceptions?
Considering a scenario in which we need to perform several relative operations on a service, what is the best alternative to manage multiple exceptions, returning to the user the specific step in which the problem occurred?
<?php
namespace App\Services\Auth;
use App\DTOs\Auth\RegisterDTO;
use App\Models\User;
use RuntimeException;
use Throwable;
class RegisterService
{
/**
* u/throws Throwable
*/
public function execute(RegisterDTO $registerDTO)
{
try {
/*
* Operation X: First exception possibility
* Consider a database insert for user, can throw a db error
*/
/*
* Operation Y: Second exception possibility
* Now, we need to generate a token to user verify account,
* for this, we save token in db, can throw another db error, but in different step
*/
/*
* Operation Z: Third exception possibility
* Another operation with another exception
*/
} catch (Throwable $e) {
}
// OR another method, works, but it is extremelly verbose
try {
/*
* Operation X: First exception possibility
*/
} catch (Throwable $e) {
}
try {
/*
* Operation X: Second exception possibility
*/
} catch (Throwable $e) {
}
}
}
https://redd.it/1kx07me
@r_php
Considering a scenario in which we need to perform several relative operations on a service, what is the best alternative to manage multiple exceptions, returning to the user the specific step in which the problem occurred?
<?php
namespace App\Services\Auth;
use App\DTOs\Auth\RegisterDTO;
use App\Models\User;
use RuntimeException;
use Throwable;
class RegisterService
{
/**
* u/throws Throwable
*/
public function execute(RegisterDTO $registerDTO)
{
try {
/*
* Operation X: First exception possibility
* Consider a database insert for user, can throw a db error
*/
/*
* Operation Y: Second exception possibility
* Now, we need to generate a token to user verify account,
* for this, we save token in db, can throw another db error, but in different step
*/
/*
* Operation Z: Third exception possibility
* Another operation with another exception
*/
} catch (Throwable $e) {
}
// OR another method, works, but it is extremelly verbose
try {
/*
* Operation X: First exception possibility
*/
} catch (Throwable $e) {
}
try {
/*
* Operation X: Second exception possibility
*/
} catch (Throwable $e) {
}
}
}
https://redd.it/1kx07me
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Kinda like Time, but this time, with distance
I’ve just released yet another distance library but using the same tricks I’ve learned from my Time Library. So you can be sure that 100 centimeters is triple-equal to 1 meter. You also have some type-safety so that you aren’t relying on bare ints/floats for distance, and then someone puts in centimeters instead of meters.
This also has some (de)serialization support for Crell's Serde library, for when you want to serialize a distance to a specific number in a certain unit.
Note: this uses micrometers as the base unit; that means 64-bit systems are limited to around the size of the solar system, while 32-bit systems are limited to a couple of meters.
https://redd.it/1kx0q42
@r_php
I’ve just released yet another distance library but using the same tricks I’ve learned from my Time Library. So you can be sure that 100 centimeters is triple-equal to 1 meter. You also have some type-safety so that you aren’t relying on bare ints/floats for distance, and then someone puts in centimeters instead of meters.
This also has some (de)serialization support for Crell's Serde library, for when you want to serialize a distance to a specific number in a certain unit.
Note: this uses micrometers as the base unit; that means 64-bit systems are limited to around the size of the solar system, while 32-bit systems are limited to a couple of meters.
https://redd.it/1kx0q42
@r_php
packagist.org
withinboredom/distance - Packagist
typesafe distance
I just published the first draft of my course on building high-performance PHP apps with Swoole
Hi everyone!
I've been working on this course to teach how to build high-performance, coroutine-based apps in PHP using Swoole. It covers architecture, async patterns, real-time APIs, and a full example project called Paw Salon.
This is the first release draft. It’s not polished, but it’s complete enough to show the ideas, and I’d love feedback from other PHP devs. Ah, it will be available for free until I finish it.
If you’re curious about Swoole and async programming with PHP, DM me and I'll send you the download link.
Thanks!
https://redd.it/1kx26ik
@r_php
Hi everyone!
I've been working on this course to teach how to build high-performance, coroutine-based apps in PHP using Swoole. It covers architecture, async patterns, real-time APIs, and a full example project called Paw Salon.
This is the first release draft. It’s not polished, but it’s complete enough to show the ideas, and I’d love feedback from other PHP devs. Ah, it will be available for free until I finish it.
If you’re curious about Swoole and async programming with PHP, DM me and I'll send you the download link.
Thanks!
https://redd.it/1kx26ik
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Pipe Operator RFC passed
Voting is closed for the pipe operator.
This (taken directly from the RFC) will be legal code in 8.5:
https://redd.it/1kx872h
@r_php
Voting is closed for the pipe operator.
This (taken directly from the RFC) will be legal code in 8.5:
$result = "Hello World"
|> htmlentities(...)
|> str_split(...)
|> fn($x) => array_map(strtoupper(...), $x)
|> fn($x) => array_filter($x, fn($v) => $v != 'O');
https://redd.it/1kx872h
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
New in Symfony 7.3: DX Improvements (part 1)
https://symfony.com/blog/new-in-symfony-7-3-dx-improvements-part-1?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1kxbhfc
@r_php
https://symfony.com/blog/new-in-symfony-7-3-dx-improvements-part-1?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1kxbhfc
@r_php
Symfony
New in Symfony 7.3: DX Improvements (part 1) (Symfony Blog)
Symfony 7.3 brings DX improvements like full Twig deprecation reporting, PascalCase string support, new form helpers, union types in OptionsResolver and a DatePoint Doctrine Type.
NODEJS CAN RUN PHP !!!
based from the tweet of matteo collina : https://x.com/matteocollina/status/1927395639698096313
i was wondering if it's only like for dummy noscripts or is it legitimately a thing???
https://redd.it/1kxcpgz
@r_php
based from the tweet of matteo collina : https://x.com/matteocollina/status/1927395639698096313
i was wondering if it's only like for dummy noscripts or is it legitimately a thing???
https://redd.it/1kxcpgz
@r_php
Reddit
From the PHP community on Reddit: NODEJS CAN RUN PHP !!!
Explore this post and more from the PHP community
How I can make/configure make:command to place my comands into a specific directory instead of the default one?
If I need a command I type:
In order to make a command upon
https://redd.it/1kxghve
@r_php
If I need a command I type:
php bin/console make:command mycommand:dosmething
In order to make a command upon
./src/Console but a coleague of mine does a refactor ans places the commands upon ./src/Infrastructure/Console instead of the default path. Is there a way to override the make:command in order to place the generated commands upon the desired path?https://redd.it/1kxghve
@r_php
Reddit
From the symfony community on Reddit
Explore this post and more from the symfony community
Built a full WebRTC implementation in PHP – Feedback welcome!
Hey everyone!
I've been working on a full WebRTC implementation in PHP and just released a set of packages that handle everything from ICE, DTLS, SCTP, RTP, and SRTP to signaling and statistics.
It’s built entirely in PHP (no Node.js or JavaScript required on the backend), using PHP FFI to interface with native libraries like OpenSSL and VPX when needed. The goal is to make it easy to build WebRTC-based apps in pure PHP – including media servers, video conference web app, SFUs, and peer-to-peer apps.
GitHub: https://github.com/PHP-WebRTC
Features:
Full WebRTC stack: ICE, DTLS, SRTP, SCTP, RTP
Adapter-based signaling (WebSocket, TCP, UDP, etc.)
PHP-native SDP and stats
SFU-ready architecture
Fully asynchronous with ReactPHP
I'm actively looking for:
Feedback on architecture or API design
Suggestions for real-world use cases
Contributions, issues, or ideas from the community
If you're interested in media streaming or real-time communication with PHP, I'd love your thoughts. Also happy to answer any technical questions!
Thanks 🙏
https://redd.it/1kxnjod
@r_php
Hey everyone!
I've been working on a full WebRTC implementation in PHP and just released a set of packages that handle everything from ICE, DTLS, SCTP, RTP, and SRTP to signaling and statistics.
It’s built entirely in PHP (no Node.js or JavaScript required on the backend), using PHP FFI to interface with native libraries like OpenSSL and VPX when needed. The goal is to make it easy to build WebRTC-based apps in pure PHP – including media servers, video conference web app, SFUs, and peer-to-peer apps.
GitHub: https://github.com/PHP-WebRTC
Features:
Full WebRTC stack: ICE, DTLS, SRTP, SCTP, RTP
Adapter-based signaling (WebSocket, TCP, UDP, etc.)
PHP-native SDP and stats
SFU-ready architecture
Fully asynchronous with ReactPHP
I'm actively looking for:
Feedback on architecture or API design
Suggestions for real-world use cases
Contributions, issues, or ideas from the community
If you're interested in media streaming or real-time communication with PHP, I'd love your thoughts. Also happy to answer any technical questions!
Thanks 🙏
https://redd.it/1kxnjod
@r_php
GitHub
PHP WebRTC
A pure PHP implementation of WebRTC. PHP WebRTC has 26 repositories available. Follow their code on GitHub.
Just made footers configurable in my Laravel based ERP.
Hey r/Laravel!
I just added a flexible footer configuration system to my open-source Laravel ERP project Samarium and thought to share with you all.
What's new:
Footer templates are now completely configurable via `config/app.php`
Just set
All footer files have access to the global `$company` object (name, phone, email, address, etc.)
Built with Bootstrap 4 classes for easy styling
Example:
If you have a footer file named
'footerbladefile' => 'partials.cms.website.footer.footer-corporate'
Had been some time that I wanted to implement this. Now that I have done it, just sharing with you all. Also, any better idea to implement this?
Repo: https://github.com/oitcode/samarium
Thanks all.
https://redd.it/1kxozw7
@r_php
Hey r/Laravel!
I just added a flexible footer configuration system to my open-source Laravel ERP project Samarium and thought to share with you all.
What's new:
Footer templates are now completely configurable via `config/app.php`
Just set
'footer_blade_file' => 'partials.cms.website.footer.footer-name' and you're doneAll footer files have access to the global `$company` object (name, phone, email, address, etc.)
Built with Bootstrap 4 classes for easy styling
Example:
If you have a footer file named
footer-corporate.blade.php in the resources/views/partials/cms/website/footer directory, configure it as below in config/app.php file:'footerbladefile' => 'partials.cms.website.footer.footer-corporate'
Had been some time that I wanted to implement this. Now that I have done it, just sharing with you all. Also, any better idea to implement this?
Repo: https://github.com/oitcode/samarium
Thanks all.
https://redd.it/1kxozw7
@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
Immutable value object using property hooks
before property hooks you would simply use constructor property promotion in a readonly class with getters and you're good.
readonly class ValueObject
{
public function construct(
private string $name,
private ?int $number = null,
) {
}
public function getName(): string
{
return $this->name;
}
public function getNumber(): ?int
{
return $this->number;
}
}
I am now trying to achieve the same behavior using property hooks, but to me that seems to be a tricky task because property hooks do not support readonly properties. I came up with a solution, but this needs reflection to see if a property is really uninitialized. working with isset() would allow to overwrite properties that are initialized with null.
class ValueObject
{
use ImmutableSetter;
public function construct(
private(set) string $name {
set => $this->immutableSet(PROPERTY, $value);
},
private(set) ?int $number = null {
set => $this->immutableSet(PROPERTY, $value);
},
)
{
}
}
trait ImmutableSetter
{
protected function immutableSet(string $property, mixed $value): mixed
{
$reflectionProperty = new \ReflectionProperty(static::class, $property);
if ($reflectionProperty->isInitialized($this)) {
throw new \LogicException("ValueObject::{$property} is immutable.");
}
return $value;
}
}
even if this solution works and is somewhat reusable, I feel that it's not worth the effort and the overhead compared to the classic solution using readonly property with a getter method.
why did they make readonly properties incompatible with property hooks? is that a technical problem or just per design?
EDIT: okay I just realized why readonly does not work with property hooks: It's because even constrcutor property promotion uses the set hook :>
https://redd.it/1kxn4gc
@r_php
before property hooks you would simply use constructor property promotion in a readonly class with getters and you're good.
readonly class ValueObject
{
public function construct(
private string $name,
private ?int $number = null,
) {
}
public function getName(): string
{
return $this->name;
}
public function getNumber(): ?int
{
return $this->number;
}
}
I am now trying to achieve the same behavior using property hooks, but to me that seems to be a tricky task because property hooks do not support readonly properties. I came up with a solution, but this needs reflection to see if a property is really uninitialized. working with isset() would allow to overwrite properties that are initialized with null.
class ValueObject
{
use ImmutableSetter;
public function construct(
private(set) string $name {
set => $this->immutableSet(PROPERTY, $value);
},
private(set) ?int $number = null {
set => $this->immutableSet(PROPERTY, $value);
},
)
{
}
}
trait ImmutableSetter
{
protected function immutableSet(string $property, mixed $value): mixed
{
$reflectionProperty = new \ReflectionProperty(static::class, $property);
if ($reflectionProperty->isInitialized($this)) {
throw new \LogicException("ValueObject::{$property} is immutable.");
}
return $value;
}
}
even if this solution works and is somewhat reusable, I feel that it's not worth the effort and the overhead compared to the classic solution using readonly property with a getter method.
why did they make readonly properties incompatible with property hooks? is that a technical problem or just per design?
EDIT: okay I just realized why readonly does not work with property hooks: It's because even constrcutor property promotion uses the set hook :>
https://redd.it/1kxn4gc
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
Best practices for PHP GraphQl response data extraction
So, as background, I am a retired Software Developer; but on older platforms (AS400, etc.), not the newer web oriented languages. I have decades of experience.
I have a website that runs a bunch of frontend HTML and PHP code. Down deep, one of my processes, runs a GraphQl query and gets back a ton of information (Arrays). that I'm using to validate form input and passing on to payment gateways. But I'm doing all the response data extraction via a bunch of string searches (strpos) and substring (substr) operations.
But I'm a bit of a perfectionist and like my code to do things properly and efficiently. I'm wanting to change my response data extractions to be more "best practice". I've seen mention of a foreach loop that appears to cycle through array to array to array processing (see JS foreach code snippet below) and ultimately appears to grab the product id. But I can't seem to get it to work for me. (I have a similar GraphQl schema to the below).
Using PHP, how can I get at that lowest level id, name and price so I can replace all my (current) string and substring code?
foreach($response->data->products->edges as $a){
// echo $a->node->id;
Schema looks like this:
products(id ----) {
id
noscript
edges {
node {
id
name
price
}
}
}
https://redd.it/1kxrcna
@r_php
So, as background, I am a retired Software Developer; but on older platforms (AS400, etc.), not the newer web oriented languages. I have decades of experience.
I have a website that runs a bunch of frontend HTML and PHP code. Down deep, one of my processes, runs a GraphQl query and gets back a ton of information (Arrays). that I'm using to validate form input and passing on to payment gateways. But I'm doing all the response data extraction via a bunch of string searches (strpos) and substring (substr) operations.
But I'm a bit of a perfectionist and like my code to do things properly and efficiently. I'm wanting to change my response data extractions to be more "best practice". I've seen mention of a foreach loop that appears to cycle through array to array to array processing (see JS foreach code snippet below) and ultimately appears to grab the product id. But I can't seem to get it to work for me. (I have a similar GraphQl schema to the below).
Using PHP, how can I get at that lowest level id, name and price so I can replace all my (current) string and substring code?
foreach($response->data->products->edges as $a){
// echo $a->node->id;
Schema looks like this:
products(id ----) {
id
noscript
edges {
node {
id
name
price
}
}
}
https://redd.it/1kxrcna
@r_php
Reddit
From the PHP community on Reddit
Explore this post and more from the PHP community
I wrote a phpstan rule extension to limit the use of transitive dependencies.
https://github.com/SpencerMalone/phpstan-no-transitive-use
https://redd.it/1kxutay
@r_php
https://github.com/SpencerMalone/phpstan-no-transitive-use
https://redd.it/1kxutay
@r_php
GitHub
GitHub - SpencerMalone/phpstan-no-transitive-use: Don't let your code use transitive dependencies.
Don't let your code use transitive dependencies. Contribute to SpencerMalone/phpstan-no-transitive-use development by creating an account on GitHub.
New in Symfony 7.3: DX Improvements (part 2)
https://symfony.com/blog/new-in-symfony-7-3-dx-improvements-part-2?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1ky60m8
@r_php
https://symfony.com/blog/new-in-symfony-7-3-dx-improvements-part-2?utm_source=Symfony%20Blog%20Feed&utm_medium=feed
https://redd.it/1ky60m8
@r_php
Symfony
New in Symfony 7.3: DX Improvements (part 2) (Symfony Blog)
Symfony 7.3 adds better exception logging, enum support in config, native PHP 8.4 lazy objects, and key-based query mapping for improved DX.