Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125039 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 18A051A00BD for ; Sun, 18 Aug 2024 04:46:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1723956483; bh=eGuRZl3YvoOcPH4V8aWz/v85X18kjW21CF3KCwTZL+8=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=DlfWjGXZKR8cQzK70RJjUHyGoXbbNUQRWyF+A2TVRdEom1ePKtkpXW5QYSuNlXaEa ZaD8OHticJrX2LLF6er/A7xNZNf33pLSXe0ffvVtP4/KK8O2LGT+G1vBm0L9GSxoJ8 Jexw8PI9ZvONrcUWKBYz6akXkabQEWio2tZzi7sCZ6QWs0j2qnSQXo5/OpYFSbN1+v rpS+PMoglQy+7OJBILdNVhcvJvRfhucL5RIwJ5fgsXO8fxdPJCLDFuT0z6IW2sik2F HTcjb/spxuWVzVm1hAvATBknV7vY15ZIm3tY4ih/oL8cZv3IqatwCnR0QknKlrEB/D FBh8fUTuhNVtg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 464A118005C for ; Sun, 18 Aug 2024 04:48:01 +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-yw1-f180.google.com (mail-yw1-f180.google.com [209.85.128.180]) (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, 18 Aug 2024 04:48:00 +0000 (UTC) Received: by mail-yw1-f180.google.com with SMTP id 00721157ae682-68518bc1407so35582407b3.2 for ; Sat, 17 Aug 2024 21:46:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1723956372; x=1724561172; 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=nh5M/T0+Tv3HXmnMmgU+re88Y0xVgEblm3TwocPCixg=; b=c32XynIR5AD/90/z6Ll1JhhpZ7H1/GaG6Az79QloU8lx22NMGUW8YCkh8BPK56Owol W311mynV2lmGJzqFG/M6X6a53H9FXf7UuKFQr879IYcJWLJj15FOmDiYFx2rg5Hz7omt zhTny3o7I/FMkjyZuCoW1rYWk/HPISYQGr8zNjBYV3pW210QhEtd2fB6W88cwI/Q7A8X kMuKhSi/LtxSSYXwv3g3fKtk1uCxCwL+gOLI0Tai1EeHEXbFnCivqlgFNqwEyZKXczl2 ogzIdPveIPq43sAiqjaBQHCgh4P70SUeUQuIRr6NeqA6x2E1ccNrsfM4KO8EZFKJs1DS vygQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723956372; x=1724561172; 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=nh5M/T0+Tv3HXmnMmgU+re88Y0xVgEblm3TwocPCixg=; b=e2moosSchTRnaMOGk5hdm6+irzwElDn+UzP0hkhAI2jwt++bkA+v6i/wRAvuTCaJwQ PXTWv5UVDfSPj3rNlDK+1Ue+sDY/oZ4vZ0fePXWg7C8v8JxDGpfjgZgTnRqNGWOv5/BZ snnFWHt0ZIHg3Q9CEZI8oBsItDDWPJyJfg5eKSU1NvZwwc7c3TtEREzRT9xwJwloy1xa VPYyZWvrTgNUcjgKcx7zP7ezkt94kl7hFF0jfIz2lOP1YYaBUqtI0yBsVQ8H4KiKqQlI Gc6GkibqLKQPOSXIacVM4veJTGkbgQBW061IU0dbXVSdZHhaCEXYLvJkDEvJMqI2OoWd OaBA== X-Gm-Message-State: AOJu0YxMhH1x58HzkSI2SFBATlzLp9GasgEkM92TabS95YzHMh9awT6t 6vm0vDOAffGR0Y6C+ctJKPPl1TA5hNYXmFWkgTW8gchA1/DkA38AD+WyYRxjyHJAtYxkfbpzgAc sGcM= X-Google-Smtp-Source: AGHT+IETDvtqJ9BGVtiaeP6cTEwE/DR6wL8XDnmHNn0MKDIWGPhE7aD/NGEy80s1HD5d1LiOLvWbqg== X-Received: by 2002:a05:690c:6691:b0:6ae:f49f:8970 with SMTP id 00721157ae682-6b1badb7bb3mr77763677b3.17.1723956371886; Sat, 17 Aug 2024 21:46:11 -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 00721157ae682-6af9e1dc6a2sm11987847b3.142.2024.08.17.21.46.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Aug 2024 21:46:10 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] Should there be a `get_declared_enums()` function ? In-Reply-To: <66C036DA.6090801@adviesenzo.nl> Date: Sun, 18 Aug 2024 00:46:09 -0400 Cc: PHP internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <66BD5F05.8010409@adviesenzo.nl> <8dc51539-20bb-4017-b859-76066e2287e5@gmx.de> <4AA66A3E-1ACF-48F5-81A2-C6AAAE8B3FD0@newclarity.net> <66BFFC0C.1090900@adviesenzo.nl> <66C036DA.6090801@adviesenzo.nl> To: Juliette Reinders Folmer X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) > On Aug 17, 2024, at 1:36 AM, Juliette Reinders Folmer = wrote: >> What if instead PHP were to implement an optional 2nd callback = parameter to `include()` / `require()` / `include_once()` / = `require_once()` to allow us to capture the symbols loaded and their = paths? The callback function could return `void` and accept an array of = `$symbols` with the following guaranteed minimum structure? >>=20 >> $symbols =3D array( >> 'classes' =3D> [], >> 'interfaces' =3D> [], >> 'traits' =3D> [], >> 'enums' =3D> [], >> ); >>=20 > Except `include()` and friends aren't function calls, but language = constructs/expressions and don't take parameters as such, so I don't see = how that would be possible without changing `include()` and friends to = function calls (along the lines of what happened for `exit` in PHP 8.4 = with non-parenthesized use still possible to mitigate the otherwise huge = breaking change), I know that those functions can be called as a function and return a = value like the following: $return_value =3D include($path); I was making an assumption that since they be called like a function = they could also accept optional parameters, although I admittedly was = only assuming and do not know for sure. Do you know for a fact that = they cannot take a 2nd parameter, or just assuming like I was? =20 Does anyone else know for certain it is would be possible for = `include()` et.al. to accept an optional 2nd parameter? However, even if a 2nd parameter is not a viable option then this could = be addressed by instead adding a single new function with a signature = of `spl_autoload_callback($fn callback):callback` where the callback has = a signature of `function ($symbols array)` which could be used like so: function loadFile($path) { if (strpos(__DIR__, 'phar://') !=3D=3D 0) { $path =3D realpath($path); if ($path =3D=3D=3D false) { return false; } } if (isset(self::$loadedClasses[$path]) =3D=3D=3D true) { return self::$loadedClasses[$path]; } $prior_callback =3D spl_autoload_callback(function($symbols) use = ($path) { foreach ($symbols['classes'] as $className) { self::$loadedClasses[$path] =3D $className; self::$loadedFiles[$className] =3D $path; } }); include($path); spl_autoload_callback($prior_callback); return self::$loadedClasses[$path]; } >> This approach would be a less disruptive than my prior suggestion > Not so sure about that considering the above ;-) Well then I think a single new function would be very low on the = disruption scale, no? > This probably needs some more bike shedding ;-) Shedding of bike undertaken. :-) -Mike