Re: `PDO::FETCH_CONSTRUCTOR` fetch mode proposal

From: Date: Fri, 19 Jan 2024 00:04:56 +0000
Subject: Re: `PDO::FETCH_CONSTRUCTOR` fetch mode proposal
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-122182@lists.php.net to get a copy of this message
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

« previous php.internals (#122182) next »