Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122090 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93261 invoked from network); 3 Jan 2024 08:36:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2024 08:36:19 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1704271010; bh=VV6sILYqDAJxEhel/0GLm7bQdfwen7J/Ti5QPRmlVvw=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=WA73HvHCrBrk0UABVnKST0Arg4mgMtQ/PnrpzpKTzjPuqlpTcMhekLQUKqstzqW/g 1bhDDHmU7lqYz7TAsSrQEMJPiBXm1rC2LHo7iPFN7iuUcCVKLseYdB1pgMYmDg8bLM FMwBfQbDJ4OXF4qoTwPTjrchw03NtfSEB+VZwtUNrTimduCwR0pRm1WHYu3Z5/t23P T4fdL+uNT3SUjXPDFLddiByNaY1CWUZ4hAbnjE/Jle08Ynx8veJlvOyZn4jba28OVR FKiFIUddRDD8PPbiiVqon8yCtA0SNaHqpDKMA5h8CzeL/wrvrKy7vFZv2WS8xwTT47 TU4G9II9U90CQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3A1E518005F for ; Wed, 3 Jan 2024 00:36:49 -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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, FREEMAIL_REPLY,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-yw1-f177.google.com (mail-yw1-f177.google.com [209.85.128.177]) (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 ; Wed, 3 Jan 2024 00:36:48 -0800 (PST) Received: by mail-yw1-f177.google.com with SMTP id 00721157ae682-5e7c1012a42so83740907b3.3 for ; Wed, 03 Jan 2024 00:36:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704270977; x=1704875777; 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=8FKXrpdeMJNkUbwu3ADbL1MaPFGeCWE+NdWqY0qmtCg=; b=lWKakFXoCQIGc7z+cvtD4FiI/4WzZIYsnPizakKxHoqTOSQ0XL6VNzvA/UNoSB5g/w IGP8cVX3xmvDxA7Z/gbzKvw+nmdQ+Y00vKP4YDNY3sa2swq5jyYxZRORN1oGm5FMHDdd cO7Qej5q9d+hMy3kajQqVpq7aV3CsPjMPyNdBE/1uDqldjkNmfr9Nh6X/J+0BWqzA+CR fehuX71uRShKbGxofEIIZ7vSMzdckQ617miHEoJt+Z0xx6OvT7VD9fJhWhYMhNaHXywu Go/ooArWmEAL1qr+Y9OiIBl9gRY+5nof0SX1MtBUEOsI90X/f3GQnL8IwFHxYCD3S6qb l+nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704270977; x=1704875777; 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=8FKXrpdeMJNkUbwu3ADbL1MaPFGeCWE+NdWqY0qmtCg=; b=mm6nWSieA0hW+v2vm+M4BnAQcvhq5zjd5lHObUCINgqKYaUcMiSRiehrqrvG0tnKex z0D4VIntq1oIGEMWg0yyEVNdcZevBfZfihJrWGbTbbgQKHro9gsN369BDKS2HMSeoNfD ZJi4DlaCL5hj42yFr5Ha+oaN4QTirW7wHFNf8FUH0EdE1MJEovcHFsNg5z48IxDIE3J8 PUfTeg+ZcX6Tt1OUQy/cS3HquAESAZan7wPobvewrvMbj2b/0wSdeoseRA/5fwZjTpei hujmpSuA5RznOWr4S3Ou031tfAJopphfcZ2kWTL4cy6EoNJ4Ybx7iRQN825Y92wGi34m STYw== X-Gm-Message-State: AOJu0YxPLex1nDVhIy6g/fQiRhlpa4dUd2D15cC2JHOCogNYhR1KnBt0 ChMtWMrqBMo29DqDsSsP4Qjl3ns2kztPB4xinIY= X-Google-Smtp-Source: AGHT+IEq5BrGpFyIhjevCgRg6txfsmm7U9nLS9JsAYHYh8WMN2MAm3v3iSe5kFivEFlkFdhJqUELLo9SOvkaWN8s/kI= X-Received: by 2002:a05:6902:52a:b0:dbd:b21d:de7a with SMTP id y10-20020a056902052a00b00dbdb21dde7amr8540386ybs.122.1704270977317; Wed, 03 Jan 2024 00:36:17 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 3 Jan 2024 09:36:05 +0100 Message-ID: To: Nicolas Grekas Cc: Max Semenik , Internals Content-Type: multipart/alternative; boundary="000000000000344127060e0682f0" Subject: Re: [PHP-DEV] [RFC][Discussion] NotSerializable attribute From: michal.brzuchalski@gmail.com (=?UTF-8?Q?Micha=C5=82_Marcin_Brzuchalski?=) --000000000000344127060e0682f0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Nicolas, =C5=9Br., 3 sty 2024 o 08:12 Nicolas Grekas napisa=C5=82(a): > Hi Max, > > Hi, I'd like to propose a new attribute, #[NotSerializable]. This > > functionality is already available for internal classes - userspace > should > > benefit from it, too. > > > > The RFC: https://wiki.php.net/rfc/not_serializable > > Proposed implementation: https://github.com/php/php-src/pull/12788 > > > > Please let me know what you think. > > > > Regarding the inheritance-related behavior ("The non-serializable flag is > inherited by descendants"), this is very unlike any other attributes, and > this actively prevents writing a child class that'd make a parent > serializable if it wants to. > > To me, if this is really the behavior we want, then the attribute should = be > replaced by a maker interface. > Then, a simple "instanceof NotSerializable" would be enough instead of > adding yet another method to ReflectionClass. > This should be possible without ReflectionClass, see https://3v4l.org/N3fmO A property redeclare doesn't inherit the attributes, therefore this might be a solution for the problem you presented. Another ad-hoc way could be implementing `__serialize()` in the child class= . I like this feature and the only thing I'd like to consider is different naming options for voting. From the serialization libraries you can find similar attributes, these are= : * https://github.com/Crell/Serde `#[Crell\Serde\Attributes\Field(exclude: true)]` * https://github.com/symfony/serializer `#[Symfony\Component\Serializer\Attribute\Ignore]` * https://github.com/schmittjoh/serializer `#[JMS\Serializer\Annotation\Exclude]` In the Java world also: * Java EE or Jakarta EE and using JAX-RS `@Transient` * Jackson `@JsonIgnore` In the C# world * .NET _System.Text.Json.Serialization_ `[JsonIgnore]` So there might be some other naming proposals like maybe just `Ignore` or `Exclude` ? What is worth mentioning are solutions allowing to change the strategy on inheritance which JMS/Serializer supports https://jmsyst.com/libs/serializer/master/reference/annotations#exclusionpo= licy The `#[ExclusionPolicy]` allows to declare that all properties should be excluded or none. Worth mentioning a future scope could introduce more interesting solutions like: * Exclude/Ignore conditionally on class or property level, for eg: a. if the value is null, b. or is undefined or c. its value is the default value - which allows to skip serialization of properties with default values that will be unserialized back with the default value - see https://3v4l.org/6b1Y6 Similar solutions used by: * JMS/Serializer `#[JMS\Serializer\Annotation\SkipWhenEmpty] * .NET `[JsonIgnore(Condition =3D JsonIgnoreCondition.WhenWritingDefault)]` see https://learn.microsoft.com/en-us/dotnet/api/system.text.json.serialization= .jsonignorecondition?view=3Dnet-8.0 Cheers, Micha=C5=82 Marcin Brzuchalski --000000000000344127060e0682f0--