On Fri, Jan 19, 2024 at 1:51 AM Alexander Pravdin <alex.prav...@interi.co> wrote:
> I would also suggest supporting readonly classes and creating special > attributes to help map data fields to constructor arguments. Something like > this: > > readonly class User { > public function __construct( > #[PDOField('user_id')] > public string $userId, > #[PDOField('user_name')] > public string $userName, > #[PDOField('user_address')] > public ?string $userAddress = '', // Optional field with default > value > ); > } > > -- > Best regards, > Alex > > > On Fri, Jan 19, 2024 at 9:05 AM Saki Takamachi <s...@sakiot.com> wrote: > > > Hi Frederik > > > > > First off, please excuse me if I’ve done something wrong related to the > > usage of the mailing list. This all is completely new to me. > > > > Welcome to the internal mailing list! I had looked the pull request, and > > I'm pleased to have received your email promptly. > > > > > Thank you, the link was originally on the text "on GitHub" but it seems > > to have been stripped. > > > > Since mailing lists are text rather than HTML, you cannot attach links to > > strings. > > > > > I hereby want to propose a new fetch mode for PDO. I’ve detailed the > > motivation for it on GitHub. I haven’t actually written the code for it, > > but it should not be too difficult. > > > > Now, I agree that it is often not possible to use `PDO::FETCH_CLASS` > > because DB column names are typically snake case and variables and > > properties are camel case. > > > > IMHO, passing arguments to the constructor in order is a good approach, > > but I think another option would be to give attributes to properties and > > map data appropriately when using PDO::FETCH_CLASS. > > > > e.g. > > ``` > > #[ColumnName('user_name')] > > private string $userName; > > ``` > > > > In addition to the concerns mentioned in the pull request, I'm also > > concerned that more modes with similar functionality will confuse users. > > > > Regards. > > > > Saki > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: https://www.php.net/unsub.php > > > > > Would it be interesting to see if there's a way to make the hydration of objects more standard in PHP? PDO could then use that underlying implementation, but so could every existing library, or even PHP extension (SOAP/XML/JSON) that does anything related to object hydration/(de)serialization. I'm looking at Symfony, Doctrine, and all the other serialization/hydration/auto-mapper library maintainers) for this because I wouldn't be able to design this myself.