Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126224 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id C3EA11A00BC for ; Sun, 26 Jan 2025 18:43:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1737916852; bh=Zc3enWl/IRUlD2u/mwVe6fFdp7ZE8iAOCrzNdR9c5Pk=; h=Date:From:To:Subject:From; b=QnxR1Necml6OelciByBuq4GrYp8r5qCAWkYixvviDxV7B0xFeA0n0AW5BC9iyNUXZ IVXNuBIpdiaEqMzXAxiUlbsAKgZOdxmI7l1ENYm/vv8sLsxDaTjMmtjuVUEZtuEb6S hk+AsgirZ8A4aTgnnexwoRPqlcoyU+HvRz3ji+NvhmGVRpPXXTspDvBeQojnUN91ze /z0HySMbVRiFqP+dcE4CFLaVnE3LMJHXK+bWEsKf8TPleTNRVQeccLMJOuWahoYG/z c4IxzIQTR16E8qmpvoeU6fPVP+teBafwKqsNuMRefHh9Lg6gr9f30B3KejEgf3l8Eo ztr375t/DweIQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B3C03180061 for ; Sun, 26 Jan 2025 18:40:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, 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-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 ; Sun, 26 Jan 2025 18:40:51 +0000 (UTC) Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-4362bae4d7dso25857415e9.1 for ; Sun, 26 Jan 2025 10:43:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737917019; x=1738521819; darn=lists.php.net; h=content-transfer-encoding:subject:to:from:content-language :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Zc3enWl/IRUlD2u/mwVe6fFdp7ZE8iAOCrzNdR9c5Pk=; b=nhjiZMcAF70fssRUloGGDlmaT12gRPolsNV2KmTDhItkluMZnFKLsWnS4Dp4EgUoQT e/QHikPI5wfGVTTh+2NHIpkVY6pYnputYOO1h0Zk/3oFWTyRux6u6HIqQffYA7z1PBmy GqlgjqNb/QIWRu4l481ZOb/FRSWgqyWVUyQOkdXW8tfOaAcHPpzHyTV0gpgZgTdhn3ox yKaBVgLeeGLGkOk5rUiCg4BSYGoMVfe0meGqBpK+2PedTTopV7PDhvCH6GLF6xDbqHYk JacH5N895AlbppsDc8+18lCyS5vjoDypCG20MbH5RruTS1zKpx1TTrBUykVBF+EpwzCj nklQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737917019; x=1738521819; h=content-transfer-encoding:subject:to:from:content-language :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Zc3enWl/IRUlD2u/mwVe6fFdp7ZE8iAOCrzNdR9c5Pk=; b=lg7sSMNhsOX41CO+CXahkLmETje949TTz1YaaL20ZQjvl/NtNp8M0NcCHarDf+9Lq/ csEkBouikKK05Dy67+sZyW1uz8zAoK8kx01ENsz34gGNgL8GCiXQ9Aa3SP5rTQMVzlpL wxRgO37aMlwYK9opxq33soZonlAZVpfm7ZTzpJPOd6KgFI27LDOrpck+CWSN+8j702F3 CJfvot69QW/ikjOpLr+DcmSSQHkewB8u0e7mXuQytktJIsiyRiqa3SFXQx6r+cVy8mf7 WQhctb8obZBaDeC1H10sR8iGvsBdyv5y6aanz7rtR7ZoJEhPiM79tefUf4fF/f+V/J4O gLZQ== X-Gm-Message-State: AOJu0Yy2871LVlUD1gaO9cyjASSlGMy4XgamGa7m8x8lH4jeW6MNII49 y0lCesX8o18gcem0Wv40XqJJGjYPtfLXjRLLRsuyhJ6bgBD4e8Cc1GDBlg== X-Gm-Gg: ASbGncuu5LwkX/dECHSl9X3AghVLEej0FOtLtK7YWF4HpJAjXcEjhjGLMMUgGjMrhkD iPdoM1Ix4yQ79mekmd6foBCzw3wQuJpCeDuzEKpEu0CYMv1G16FLE1TeUGrMrlQwtkTD1+IQvcK NXvgzUGNjXyzFfnrs3Yy8IkvwPMwwGczvvlM6WgSSgOb/mn5O9cPmCU09rHfoVHRUUAPkxkApGt fvFGfiwPyt7s/3SsG8D3uPqzf2WrhkZolQ4SHqHfb608vCw2EuWYIBQR22hiR5DLt4A1M/Tpi0S OScamQie6nDPvXaRntYStXD159nVlEdpBKPqjrZpsTOfrkrfHjLQfsetb1I96CyS1TS91twFqbN CO3+tyKf/dUMAeqx2kupNt5CeeQ5VvLBpwG+FcuPtVGs+ X-Google-Smtp-Source: AGHT+IFAo2LeJS9pxRzCMNHy2otvhvbFMwnGwpBDEtXfqrqA+ZLmX1gJLjeFrmn1BuOvcMYmmRjwSg== X-Received: by 2002:a05:600c:46cb:b0:433:c76d:d57e with SMTP id 5b1f17b1804b1-438913c6801mr367032475e9.5.1737917018869; Sun, 26 Jan 2025 10:43:38 -0800 (PST) Received: from ?IPV6:2a02:1811:cd2f:3500:e093:fcad:4f6:e542? (ptr-du5vm7f5ekzptmf0fgi.18120a2.ip6.access.telenet.be. [2a02:1811:cd2f:3500:e093:fcad:4f6:e542]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-438bd5730a6sm101667025e9.35.2025.01.26.10.43.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 26 Jan 2025 10:43:38 -0800 (PST) Message-ID: Date: Sun, 26 Jan 2025 19:45:07 +0100 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: PHP internals Subject: [PHP-DEV] Behaviour of ReflectionClass::getStaticPropertyValue() for uninitialized typed properties Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit From: dossche.niels@gmail.com (Niels Dossche) Hi internals I'm looking for feedback on a bugfix for https://github.com/php/php-src/issues/12856. Fix PR: https://github.com/php/php-src/pull/17590 Basically, calling ReflectionClass::getStaticPropertyValue() on an uninitialized typed property currently returns a value of type UNDEF. UNDEF is a special internal type that should _never_ find its way into user code. The reason this happens is because of an implementation oversight: uninitialized typed properties are simply not handled. If we compare the behaviour with ReflectionClass::getValue(), then we observe that getValue() throws the typical "must not be accessed before initialization" error when accessing an uninitialized typed property. We could make getStaticPropertyValue() throw this as well, but it gets a bit awkward because it has a "default value" argument. I.e. its signature is: getStaticPropertyValue(string $name, mixed &$def_value = ?): mixed The purpose of $def_value is that if no property named $name exists, then $def_value is returned. If no $def_value is provided, then a ReflectionException is thrown with the message "Property ... does not exist". The awkwardness with making it consistent with getvalue() would be that we would throw on an uninitialized property even if a $def_value is provided. So the alternative idea, the one implemented in my PR, would be this: - If the property is uninitialized, and $def_value is not provided, then throw a ReflectionException with message "Property ... is not initialized and no default was provided". - If the property is uninitialized, and $def_value IS provided, then return $def_value. - In all other cases, the behaviour stays the same as it was. There was also some discussion about the pros and cons of different ideas in the issue thread. What do y'all think? Kind regards Niels