Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122185 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37128 invoked from network); 19 Jan 2024 09:47:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jan 2024 09:47:48 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1705657708; bh=6XC/THS2ey89n97qvGx9JruXfxWx6oT1Zejlzs8LdQg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=IG1SMWLalOMWS3EpdWxSUS5DHLxocAYWvAdVFI1U9QB69ov1RS65paNhw8lHyqYxN nVG/8Kw/BemQnCJeqNzRcg3VBem1sQ1PQ4uvZGJmSpQFguW9uNL3QGYaLLHm6dNx3y 3Ziq+rBxK87W1RerR7Yd46PV1xmqnXCh0cnTqpagmWAW2tuDaPGMMqEYM7Nd6AX76x 66/y4b4k9kaPDOQD1pTLs7AQLS8R89FeTLuyj1TkG2WEOoCdljQB3rK7KVP2n+Jvwh 9Wkw8+cipvOHRXdRlFu1KZYufbh5Otn4uztcCQvEvMWarER083ZJBwZ84VPSdGhC6y ujOBPZgINHTTw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 73AB018004A for ; Fri, 19 Jan 2024 01:48:27 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 19 Jan 2024 01:48:20 -0800 (PST) Received: by mail-lf1-f46.google.com with SMTP id 2adb3069b0e04-50e7abe4be4so691873e87.2 for ; Fri, 19 Jan 2024 01:47:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705657658; x=1706262458; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=eAJs4m9FKlpvahae8BMHsQX1Zt/XCwJiVmcO/jGbYV8=; b=iQd3pimGffi0zn6SshRsWszmCb62TfRvZrcuedSPUxF7rIVdKVVaYFbzXAxq0EEWNX MG+OTUJi2cOb/YjDOdSilTsR9LB/QacB+rYEjFpeOym0V8wEzacg6nj+VKFdFRuxORza RovFYSZWG9F2Pg6/Afh3t9f29DnpaLZsjw7l5sIee705fURVWdUUh+JWabhDgZ7Sx6RF V8PirU6cLwQ44JIU0yWB5MiviD6OpyHiybibDZRes/GRxcN6yxJvIoaBM0gJqTV+RWIq SruIGkoF15S10Q0LsekLBBmxSdhcs0M02qWhbz3+92Tb+2mzn0Q50gZb/yHQ4opr1W48 G+Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705657658; x=1706262458; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=eAJs4m9FKlpvahae8BMHsQX1Zt/XCwJiVmcO/jGbYV8=; b=NXZj/UEFresodXr1aiYgooztQ+mJz+05X0kj40KmWyUPSXDHJwLi1TrWILMN0nAKwq nasUIgCTGMq975LWYzXn4jKY7agi2GHaSJvwR51eG0S8KP90CyI404BOKFLlkVNIFbnc qgq+oDtVSIlXQxKlaSMvh+GHm0PfsQlYE57rmfmXW1D5NwOk92DKsnlxwNGGwdUjq/D7 kzkwUqNuIb6CudvUNqsvuL3f3s+oikcjdn5XqVPxK7N0cB5uPJVO4ETkZuSlgum4dXEC yLICjifL5f1eW9yd+8DLroFPnldivY0VOA4HmI1WIqsHC76ApmsluwS1ljsO7msjsJ9b OK6w== X-Gm-Message-State: AOJu0YxJ2oNIclO4AGi3SCC81iUx6CD2xpdwRMXaUTUbOyXlIfdibEK/ hptXA2I21XsS9A38mA/eH5VH3+/ANmtosW0kjgLq4cb4GLF3vSka+c7a1iCofUKyDeJn347QJGy OyQfF2hgJB4qQ5mn0zW/zVZAAyp0= X-Google-Smtp-Source: AGHT+IE643p0GOIkmzF+tfZQntZlgnoJE4VMLIIXcEjvxGur0Ms8cZx3loE1eVNzcc4FhyH054jB8FGEM0fmUHtLtvo= X-Received: by 2002:a05:6512:1114:b0:50e:6d4f:6915 with SMTP id l20-20020a056512111400b0050e6d4f6915mr685186lfg.47.1705657658314; Fri, 19 Jan 2024 01:47:38 -0800 (PST) MIME-Version: 1.0 References: <6246AF4D-C204-443C-9056-F662E59AA687@sakiot.com> In-Reply-To: Date: Fri, 19 Jan 2024 10:47:12 +0100 Message-ID: To: Alexander Pravdin Cc: Saki Takamachi , php@xpple.dev, Niels Dossche , internals@lists.php.net Content-Type: multipart/alternative; boundary="000000000000d512c8060f495eb9" Subject: Re: [PHP-DEV] `PDO::FETCH_CONSTRUCTOR` fetch mode proposal From: kjarli@gmail.com (Lynn) --000000000000d512c8060f495eb9 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Jan 19, 2024 at 1:51=E2=80=AFAM Alexander Pravdin wrote: > I would also suggest supporting readonly classes and creating special > attributes to help map data fields to constructor arguments. Something li= ke > 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 =3D '', // Optional field with defaul= t > value > ); > } > > -- > Best regards, > Alex > > > On Fri, Jan 19, 2024 at 9:05=E2=80=AFAM Saki Takamachi = wrote: > > > Hi Frederik > > > > > First off, please excuse me if I=E2=80=99ve done something wrong rela= ted 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, an= d > > I'm pleased to have received your email promptly. > > > > > Thank you, the link was originally on the text "on GitHub" but it see= ms > > 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=E2=80=99ve detai= led the > > motivation for it on GitHub. I haven=E2=80=99t actually written the cod= e 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 an= d > > 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. --000000000000d512c8060f495eb9--