Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114379 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 38076 invoked from network); 11 May 2021 13:05:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 May 2021 13:05:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 90C971804CC for ; Tue, 11 May 2021 06:12:47 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-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,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 11 May 2021 06:12:47 -0700 (PDT) Received: by mail-ed1-f44.google.com with SMTP id di13so22807105edb.2 for ; Tue, 11 May 2021 06:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=t7l+WoYCNZjhNQGa0kgGYSBoo86OIt0R+Dq7ULylA84=; b=fY0CRPSCTJnbGeTp67FvALkXMR/yQef36VcRI9U4GZVHmNukkh9t/cj8iCnhSj9ew9 eA8ZC5dWndkI99ptKMtZsRKjGEnWcuse3Z13RYUqTaWpGh09Pyt1UWB99fqNTSis5Rig OjncLtD7OKZwxnJCQbdqBScz2ZzzEQeiOAR0DdQGkm3/rCrPRIr7oVFo5NMytVcJSLDV 2HDh2UUDVXIDyqAFGDBS7PCysRwGEOx/wTdfEr4gGvvHaxvqoUzygH+SXy4OuspIK/Ve cBlsgSPLuPD5HDUlGx9Mrmji41FTsZDKsjNeOOQR3iU1P+uj5URBS1+nhfOZhvZpd4W5 FS2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=t7l+WoYCNZjhNQGa0kgGYSBoo86OIt0R+Dq7ULylA84=; b=ltM7YvVUfZz5m2iDjXIIGTEYsxz6SFH/kaPbcg7pOx3IzZRnIhT8BfnyrnxsGGsKHz Epu5ja2rfvGadJfEo5FY41dlD36NYa6FPtLQ3gzGcYbSQ8AcMRYEeerDFZCPu6UsLwHv XZYfO9UPyV+K2QtdKorMKxM/LltgRonzkkTtZDfxuhOXDt74ZxrhizoCFuhZcjD/sTd5 RZiDvj0Y2arT9mayVXEzfMdwavyM5CW7+14ipBKwqqzbL7LHxlWPmCtULOSSIs9DQS2u 1AhKiJwHn8XF3o6jINPQJ8sZI+EQhQiPHHdb3ZJSrkRlDDBgDHxLc63lMdPaNYxXVxAz bmXQ== X-Gm-Message-State: AOAM531W0swosaoKAzfavRg0EYXVx01LNtINeByS02wj6Gict14vybkc sy8jBcwaMt6+AHdafzYbz9XgSgBJtJs= X-Google-Smtp-Source: ABdhPJzWU05BjW7Kt6GIeE6+jdPiJqJG7i7FnOy3aSnLw0ENEo3NpFf9kQpjr70YXQRYD8altuJW7g== X-Received: by 2002:a50:fe03:: with SMTP id f3mr36147558edt.92.1620738766020; Tue, 11 May 2021 06:12:46 -0700 (PDT) Received: from ?IPv6:2001:983:6fc5:1:ac08:7366:57ec:ce84? ([2001:983:6fc5:1:ac08:7366:57ec:ce84]) by smtp.gmail.com with ESMTPSA id u23sm3512805ejx.49.2021.05.11.06.12.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 May 2021 06:12:45 -0700 (PDT) To: internals@lists.php.net References: Message-ID: <3f3cb374-23d8-9d26-4ea2-fe891538a7b6@gmail.com> Date: Tue, 11 May 2021 15:12:43 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] New in initializers From: dik.takken@gmail.com (Dik Takken) On 11-05-2021 11:56, Nikita Popov wrote: > > An issue for using new in (non-static) properties is that these objects are > going to get created even if the constructor doesn't run. This could be a > problem for things like unserialize() and anything that implements related > functionality in userland (e.g. Symfony's VarCloner). In particular, this > means that the default is *always* going to be constructed and populated, > even if you're bypassing the constructor. Of course, this also happens with > other property defaults, but in this case object construction may be more > expensive (and possibly side-effecting). That's not great, and there > wouldn't really be any way to avoid that. That sounds like a bad situation to me. > The alternative would be to instead only initialize such properties in the > constructor, which comes with its own caveats: We'd have to make all > classes actually have a constructor, and you'd have to make sure to call > parent::__construct() even if there is no explicit parent constructor, > otherwise you might be missing some property initializations. This also > causes something of an asymmetry between "simple" default values > (initialized on object creation) and "complex" defaults (initialized during > constructor call). The requirement of having to call the parent constructor would start making sense in case we had a built-in base class that represents all of the features that any PHP class has by default, including a constructor. This class could act like an explicit base class that you can extend in order to inherit the property initialization feature. The idea is similar to the so called new style classes in Python where you extend "object". This base class basically contains default implementations of magic methods like __init__(). So the use of "new" in initializers would require extending this base class and call the parent constructor. Maybe forgetting to do so could throw, preventing initializers from silently not working. Regards, Dik Takken