Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108324 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6733 invoked from network); 29 Jan 2020 23:01:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Jan 2020 23:01:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D3D971801FD for ; Wed, 29 Jan 2020 13:12:09 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qk1-f180.google.com (mail-qk1-f180.google.com [209.85.222.180]) (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 ; Wed, 29 Jan 2020 13:12:09 -0800 (PST) Received: by mail-qk1-f180.google.com with SMTP id w25so800111qki.3 for ; Wed, 29 Jan 2020 13:12:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=4wRDmLpQnKb5FfgOFGHTLJZIzFtUTB9Kc9S13GSU4eM=; b=LqffH+jdAZpjokc0WD7IlJHd1biM5Az/cAK+nNQ3PtmPww6p7/4tzYKs8L9Hij+uR0 kKzuxKmuFU5em0bw35Qmwfec6YvqKNrFQpPOMnHOf9v37yCR2tP5A+eskUdMCeBKc6R+ dRmtTJaD3anBj+YK436+CZMsN9BdAr526xe0RBXjQfUT4cTYm+0jm5QOkVPKU14VZJhG 37ghsYQ6EOUaUTHMeIpVcX2fuc7PA2vnuvCfM2InuLzPNMNpLaMIYdm/V5yahB/GYy29 saqOEL6GfXaR4Rj7Qe0ZFeidaSWIy+bEZRipvdJuvCxKJOURLtknEgjyNmeLpdlmIe09 dxdg== X-Gm-Message-State: APjAAAW3woGOtKdGdRevfkVOmHrTcnMWNi94jUN4I9GObe8m4UnW+p10 76p5Jj48vBVAoxIljHR+UDPIFO9rz6lXks9mDDc= X-Google-Smtp-Source: APXvYqzxCAZflj6V1Fy2SSx1smRVCo2ZhvD5ktiYjzi12xe2A4x3Sl+8XRdLomRhu2YF68v0KmuUG5oGdqpbGM37btY= X-Received: by 2002:a05:620a:1001:: with SMTP id z1mr1659420qkj.99.1580332324549; Wed, 29 Jan 2020 13:12:04 -0800 (PST) MIME-Version: 1.0 References: <244D810D-4C45-4D02-A0B7-E625090C19A9@gmail.com> In-Reply-To: <244D810D-4C45-4D02-A0B7-E625090C19A9@gmail.com> Reply-To: bishop@php.net Date: Wed, 29 Jan 2020 16:11:28 -0500 Message-ID: To: Claude Pache Cc: Marco Pivetta , tyson andre , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000d4f7df059d4dca8a" Subject: Re: [PHP-DEV] [VOTE] declare(function_and_const_lookup='global') From: bishop@php.net (Bishop Bettini) --000000000000d4f7df059d4dca8a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 29, 2020 at 3:12 PM Claude Pache wrote= : > > > Le 29 janv. 2020 =C3=A0 19:42, Bishop Bettini a =C3=A9cr= it : > > Cons... have to enumerate everything, potentially lots of work to do that > to update old code to use; edge cases I'm not thinking about. > > > Not only it is much work (although it could be partially automated), but > it does not make much sense. > > I=E2=80=99ve taken a random file (~650 LoC) in the codebase I=E2=80=99m w= orking on. With > `declare(strict_qualify=3D1)`, I would have to add: > > use function > array_filter > , array_flip > , array_key_exists > , array_keys > , array_push > , array_unshift > , compact > , ctype_digit > , idate > , in_array > , is_int > , is_string > , ksort > , ob_get_clean > , ob_start > , preg_match > , sprintf > , strlen > , strncmp > , substr_count > , trim > , usort; > A fair critique. Under the "goad use of wildcard import" pro, the quick way= : use \{*}; Any unqualified name is locked to the global namespace. > I don=E2=80=99t see a clear advantage in declaring more than 20 global fu= nctions > in each and every of the hundreds of files of the codebase=E2=80=94where = it is > evident that they are all global function (no, I don=E2=80=99t have a nam= espaced > version of `is_int()`). Also, I think that there are better ways to > discover if my colleague introduced surreptitiously a `system()` call in > the codebase. > Well, first, it's faster as Tyson described in the RFC: those are opcoded and bypass the namespace lookup. Second, and I find this the best reason, that enumeration tells me quite a bit about what that code does. I don't need to see the code to know that it's compute oriented, doesn't touch resources (eg files), and is doing what PHP does best: string and array manipulation. It also shows me that code's doing output buffer manipulation, which seems out of place and suggests that should be refactored out. IOW, it's a really nice abstract / summary of what the code's doing. And that's some very good insight. > Some time ago, I=E2=80=99ve tried the alternative approach in two files: = adding a > backslash before each and every global function (carefully avoiding > non-functions such as `isset()`, `empty()` and `list()`). Well, it remind= ed > me of the good old days when I used TeX intensively, but objectively, it > didn=E2=80=99t make the code more clear or more secure (I=E2=80=99ve not = tested its > velocity, though). > I agree: qualifying the name at the usage site doesn't add much value, IMO. It's frankly more noise than anything else. --000000000000d4f7df059d4dca8a--