Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124404 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 4C97F1A00B7 for ; Fri, 12 Jul 2024 07:10:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1720768338; bh=mfksRGLCfsLZeJxIGvlpoIF8YaSlJDmbnFxfw78bVVo=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=Sa+SioVZROUO7WuJ/hUbAYw6IuTqawq5oPvGU68NkWmP1Op4Zkbb2EHGdrHKzbeAV 4lZJmUOi7nG0BJ9haeI7x8VGOMPwmHmv5SnioLbSH+GExhwZMM0eDvC6ZzGudpKek+ kr7b1Uuov/QAvCcIIsf4rNVOfQEmITF/9nLACzW24WGYFxoHwZH1aPstUTEldkrUto MBxwCXwPEqHFi/ePwlx04FbJVi4wd62717xX6GFpy/ZitlLbn+odoGysn0S8IL8Hsc 1x1r5UjYVq7qX72bTVTfTcK0FtPVkabLXtiVclWDQucK8q+MbbkhhNX9dUj/1lV+Wa FQt4LoAV798dg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E872D1807EA for ; Fri, 12 Jul 2024 07:12:17 +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=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (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, 12 Jul 2024 07:12:17 +0000 (UTC) Received: by mail-yb1-f175.google.com with SMTP id 3f1490d57ef6-e057c25dd34so1554555276.2 for ; Fri, 12 Jul 2024 00:10:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1720768250; x=1721373050; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mfksRGLCfsLZeJxIGvlpoIF8YaSlJDmbnFxfw78bVVo=; b=vCmOqjmyG0CmoexqGYKOu6BpxaxLllJMbgsApYjp2ZvM6HCw4Dx3MHGSsPA3Cr1rpO IyX1dDiOKr40Jo1/w84IGmZWvQ8Qwocgd3IaHNLrfL879fOLprJuTXMdBxSfupeBWngs ddjrWyT/OQBb2nmVqCrXFP0LP2gkUWjbkua9jQEr8jT2mvkS2ifXNKrxjQXthP7bQLM2 ypHCQeb5YOzX6E1oARbVzo8YdLgaC62bxTB0rG0ie9+4av9xJ9ZVNGIDOjEMk61Gaggs ZvkZryx4MwOR3awzZHIOVnTPn4zb/AwVjVyT+ep2Zmxg5otLD2eFyoqFtxIrg4ORx9uq +Lkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720768250; x=1721373050; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mfksRGLCfsLZeJxIGvlpoIF8YaSlJDmbnFxfw78bVVo=; b=bkuDXa2ZmHobL01I5qYBGKGanScPqe/1querqCirhl7KNXDwvmSPvKRE2xbb/9wyCa k+8Gq7MGWE7/m61m5cf/6Au/2xRyQFiRgvAPC/McaHqOcB2p62j+j14hFdaH4n/ezLjb CHD0Opw67O+SGYjkYlgUnwvF32Hf0SaKhA1YMXLT4cpNQw+AZG2EcN5lyrsykoz5yCED qHtnickR6sryPvuC4IYQGaDYSQeggzucJCq+mo8MzCVdtjZyRYMtPY7BCRBQK6+aQ4dZ bt3uMahDGMGCnckho56xtNA2EVUuromBCvCeU11y8f6B/NWs8hzDlWasY3PtmiAWdDWE PxJw== X-Gm-Message-State: AOJu0Yz6gMVVccnic6yeL51KT+k+z9zF7aL5sQZUi3Bj5sqqncZNglmY /i6VoR7Q8XOGU23RyjRwAIM8eToUATP4W/RsqtlnIQIcU9wtQO51N1xlCYPEpP4NzhMImh7jbct huqM= X-Google-Smtp-Source: AGHT+IGpQ6yoMy61ZIv53wwWl7gr/mMDnqckskbOn1JvNnS4DBCBMwntjKauvk/A9DA8ItxX/205lg== X-Received: by 2002:a25:a069:0:b0:e03:53f0:2438 with SMTP id 3f1490d57ef6-e041b034886mr11828834276.7.1720768249807; Fri, 12 Jul 2024 00:10:49 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 3f1490d57ef6-e041a8ac964sm1209033276.6.2024.07.12.00.10.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jul 2024 00:10:48 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] [RFC] Static class In-Reply-To: <132b86de-f571-4611-8b9b-35ae107901f0@scriptfusion.com> Date: Fri, 12 Jul 2024 03:10:47 -0400 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <4596aa73-cfd4-2292-7191-2839a5bab695@php.net> <132b86de-f571-4611-8b9b-35ae107901f0@scriptfusion.com> To: Bilge X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) > On Jul 11, 2024, at 8:14 PM, Bilge wrote: >=20 > On 25/06/2024 16:17, Derick Rethans wrote: >> we shouldn't be encouraging static classes as=20 >> a bag of static functions, that ought to be just namespaced = functions. >>=20 >> cheers, >> Derick >>=20 > Can someone clue me in as to why grouping related functions in a file = with nothing but a namespace is strictly better than those same related = functions grouped as members of a class? It doesn't have to be Larry or = Derick, because even though they have expressed this view, I am aware = they are not the only ones whom hold it. Anyone who can shed some light = on this perspective is welcome to comment. I cannot answer your question as posed but I can give you a = counter-reason, one supporting the use of static classes as a bag of = static functions, at least with the feature set of PHP 8.4 and prior. =20= If a developer needs to hide global state =E2=80=94 and there are valid = reasons for maintaining global state using static classes along with a = related set of static functions. Minimally, when using streams with = include*()/require*() e.g. include("myprotocol://${handle}") namespaces = simply do not have the necessary visibility scoping features and thus = are not an option. I am currently working on a PoC for packages in userland that uses = static classes exactly in this way. I will hopefully be able to share = working code for that soon. -Mike P.S. None of include*()/require*() accept a stream context AFAICT. If = they did a developer could pass in a dependency object as a context, but = currently (again, AFAICT) there is no way to associate a dependency = object with an include*()/require*() call. The only approach I have been = able to identify to allow access to retrieve and update a dependency = object is to use a key into a array in a private static property with = public static get/set methods. =20 If context were added to include*()/require*() and/or visibility scoping = where added to symbols within namespaces then this use-case would no = longer be an argument for static classes. But unless and until then, = static classes are the only way to go. #fwiw=