Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126337 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 905F21A00BC for ; Fri, 7 Feb 2025 16:35:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738945988; bh=EqL2cNbQebAS0GPO+x9U61jdQ8X7EFTb8LdwPoDSNSQ=; h=References:In-Reply-To:From:Date:Subject:To:From; b=Z60quWkB6h1hobemT2J6ePZLi55sR58TRVDtO7QQ4dv2lEGN1xSq6QFMwr0/+KpfG JEas+aFn385BK77oQWlve7u52zKH69gQMGzklMBu/hBIrdY8RXuUDNnECLYRtw7O9S XmbcTaa2WK60bJhPMTxHz8pVW4gjMn/bMbXMoGBa5NMCOYHWgPW5SoOzfZsLOLjS/G /Cpu5Fjt43j7ThBiEEnNNuapk4iOx54VzwkHILCl/GTMSlWGJxWEnLNRMicfAK3JP4 gro0OzxP7DjCiGGswCR5ou4YZvUJKb8v8RukTofYx1lSThAEuiubhdBsI5+txEO69t KuUQ//Qmp3NDg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9532018004A for ; Fri, 7 Feb 2025 16:33:07 +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-qv1-f46.google.com (mail-qv1-f46.google.com [209.85.219.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, 7 Feb 2025 16:33:07 +0000 (UTC) Received: by mail-qv1-f46.google.com with SMTP id 6a1803df08f44-6dd0d09215aso17611836d6.2 for ; Fri, 07 Feb 2025 08:35:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738946151; x=1739550951; darn=lists.php.net; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EqL2cNbQebAS0GPO+x9U61jdQ8X7EFTb8LdwPoDSNSQ=; b=Z/Iqu59WrMT6qj9A3SJBIJQEnYavbdCQ1PI7VH12o1tqVsMApo7TuDZ2t7ynUTCQQP v/PcxTsI7qqMZGZzGBP5ly513qcwmeBuOvZdXykqc8WbQxbc+Ryur9xE4583R3ve5R5b u9dn6up4QgKEm0+0RJ7ZlKGAVjARuQHtn3tVRrcFGIwpFCU/UTWYHFcuprMh/Xu1sbAS E7TQ50vQ1F9kCLDE5DpWoC51sO8ppj17J46PBiIDqNMwyX4oRTCvUELvGsbuKhJlHPTG O5/gbhMWDTNPodn/6hiwIP8nQf9qSGA88uGxD6AtSw+WQRi5H1dnZQjbQayqjfkI/kb6 yz5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738946151; x=1739550951; h=content-transfer-encoding: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=EqL2cNbQebAS0GPO+x9U61jdQ8X7EFTb8LdwPoDSNSQ=; b=mxSGWyR++srbv+aS8REW5GdWT3mpbhwtuDaDmCvC8KiKMEpOhV/rILhyruqq/GWsQz cpT+HOCLggmlQQ9nsuxvzQPrDTRQ8VrCWE9l/dADiRATJaxpcl0sesZwaeA+5dblYDFl WakKDofDqFvm1zxhiVdz32j75cAbHDvZjdj1zd0wQNo6WzmNeMyIEF5Yv5EotxNLuSJk l5SOxlQbWsefmZYGhW4byZqqkFr/JLxr9dCxX3CtQpYFtX0zFCAZPk7dHsHrS3L+0LUJ fTw1Pg125TZBUcpdBRY2u/KOLw///Qc4vT7MpsSgVo+werHo7BEFbFj1ENNw4J5BYGAx tNPw== X-Gm-Message-State: AOJu0YzdvtYVRbqFStAOxV0YDgYgRjmwvNTyCX2+ypGtCDMbIw0z7GAk QJu/LnhCq8NuMlhbBY12J7aII1/BgojYdmDbVQHc3emGEex1/OBRHu0Ph6thSYS2Q3UGJIzMd7l FX3hlsn1eUb9HgCDZygD3/VZFZ48ldvWQB+CCwA== X-Gm-Gg: ASbGnctbdzFBSJ2IvG7rg9fxgSZ2nJeZTFr34qlZBSnkjaNF+cwcwnmeV6uSjFnYb6H FqGxmJzmNLAG8lPKb93MdylUeTyN3EQGXB7WlSpyd6MP4lr2QbVgvkGcdSvI9yrI57CXDDXQlxj 9zQFW8sYVGEg/TQkd1rS0FbMbPjS0zspM= X-Google-Smtp-Source: AGHT+IHOTpnmO0vWTHSxoxGBnY1/NpFGPnmNcjxSabprqaHC68yDRmL/j7KQX7UcAUE/oBy1VnpV1ZCjMrkqYFsgF8A= X-Received: by 2002:a05:6214:1d0d:b0:6d8:9cbf:d191 with SMTP id 6a1803df08f44-6e4455e6f16mr58923516d6.12.1738946151274; Fri, 07 Feb 2025 08:35:51 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <4bad8c629e2402b94a125e54da972586@bastelstu.be> In-Reply-To: <4bad8c629e2402b94a125e54da972586@bastelstu.be> Date: Fri, 7 Feb 2025 17:35:40 +0100 X-Gm-Features: AWEUYZky0S0KCjBBtOwb2Xx45pl7NGL2JMO3u_9RpaNe7xZZGF9NB5F0VJ_TBwY Message-ID: Subject: Re: [PHP-DEV] Short class syntax and inner classes To: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi there On Fri, Feb 7, 2025 at 4:07=E2=80=AFPM Tim D=C3=BCsterhus wrote: > > I believe Ilija has some proof-of-concept regarding file-private > classes, which would sidestep the above problem of disambiguating static > member access. Indeed. I shared a draft internally and responses were mixed. https://wiki.php.net/rfc/private-classes-and-functions https://github.com/php/php-src/compare/master...iluuu1994:php-src:private-c= lasses The RFC proposes to allow declaring classes and functions as private, which will limit their usage to the current file, or more accurately, to the current namespace block (i.e. namespace {}, not namespace across files) The motivation is to allow declaring small helper classes (e.g. mocks for tests) in the file where they are used. Of course, this is currently already possible, but discouraged to preserve the ability to autoload classes. However, autoloading is not necessary for private members, so this concern goes away. Furthermore, private mangles the class/function name so that it doesn't conflict with other files declaring a class/function with the same private name. For example, multiple tests can create a private class DbMock without worrying about conflicts. To summarize, the main benefits for private is: * Single-use classes/functions live closer to their point of usage. * It signals to users that the members are not intended to be used outside the given file. * It avoids naming conflicts for cases between private members. The main pushback was that "private" does not sufficiently indicate the semantics of this feature. This could simply be solved with a different keyword. I guess for others, "namespace private" is a more interesting concept. One thing I disliked about the implementation is that private members still pollute the global symbol tables. That said, it's not likely to matter in practice. Anyway, I didn't have any immediate plans to pursue this RFC, so feel free to take over in any way you like. Ilija