Re: `PDO::FETCH_CONSTRUCTOR` fetch mode proposal
| From: | php at xpple dot dev | Date: | Fri, 19 Jan 2024 15:53:24 +0000 |
| Subject: | Re: `PDO::FETCH_CONSTRUCTOR` fetch mode proposal | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-122193@lists.php.net to get a copy of this message | ||
Hi Alexander,
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 {When the constructor is used to create the class, readonly classes should be automatically supported by this new fetch mode right? And indeed, it would be useful to use named parameters if available. I overlooked this possibility in my response to Saki. Kind regards, Frederik van der Elspublic function __construct( #[PDOField('user_id')] public string $userId, #[PDOField('user_name')] public string $userName, #[PDOField('user_address')] public ?string $userAddress = '', // Optional field with defaultvalue);}