Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121855 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 97117 invoked from network); 29 Nov 2023 09:02:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Nov 2023 09:02:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 93E2D180055 for ; Wed, 29 Nov 2023 01:02:40 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, MISSING_HEADERS,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-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (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 ; Wed, 29 Nov 2023 01:02:40 -0800 (PST) Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3b3f55e1bbbso4135555b6e.2 for ; Wed, 29 Nov 2023 01:02:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701248551; x=1701853351; darn=lists.php.net; h=content-transfer-encoding:cc:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=XE6Hd3r9AlN+upAx361Cej9cx64XwSZe7JB28B/jfHo=; b=Dyryrz2MyiNx8aPjealMH26A+JVHL3v9DeTp2Xv3Jgi+CAunEZI3v2gRqwg09lMF2w a57XHUM7F5SB2JPc68s63KjFlowGPI17UoZw+oZcGOMN/YkBSMLTPx+318gehUvxIvPw M+8qnkZmFtMcL9cm3rUwJ7gDNr/VdbVe2sQFoiWuo+Kss1g0ZDzXnjpXZ+AhIRXXp70c x3eHn+4xdjf/Tn4D1IjCMHHRdSGACgt0+xxZTaAWwMD7V4CpItFlUULJm3CD9mAqgDHh FQSjcfKissUlVfHeQ6r7wqtCisJ23ZNoAhiaF9Ttt6ws3IGmNqyjje+TRFUtShmiBZiO UVig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701248551; x=1701853351; h=content-transfer-encoding:cc: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=XE6Hd3r9AlN+upAx361Cej9cx64XwSZe7JB28B/jfHo=; b=jDRhWYd8lNQJ6YVypgzBMp6zo8DsmfH8D57Mt7BBm5ZLTORSzgjNm6mtEOH+LfH1HT uBJVNwSqrdkugm8Cn5UbUeo6zRkt5JmEHCnLIr1k8PZuc5jqjMl9nPiHoJ7r0hHCuT9S hVNkuFWVi35cZF5cNe9bSJeZgCjcKZ5yYpChgrm11srTrkNCMxEPiStcSnqpKXNrLOHg T0gjcYcfZIu8d1unPGjb89OsD6jWzRY7h2uZjsDlJsn9XTPLUmxcZjHzDs9XzkCRFeiC Q2Ai7gqf0kiapXX2qJ60ifEYX9ZA5/x49SAs/n5xTNRbHPdCNy1l1Tp/B8mk5+4JFha6 hrpg== X-Gm-Message-State: AOJu0YwCpOA0t8xu04QSBLxjHe+YuiB0GfHZwstDaMlY3xEYbanatAFa 3NPppHaRv3/knNfoq6NMh3/qgT5g6rbqLTjkAKpI60wXScfK+Q== X-Google-Smtp-Source: AGHT+IGN9SeVk2vZzzjsuJJm3T4sXoiPYhKjfMHt38ULRGnbOK9tT/akk9jOA6ytH4Wlna87BHvLvdxYiOVZcT5wsBA= X-Received: by 2002:a05:6808:309c:b0:3b6:cb02:533b with SMTP id bl28-20020a056808309c00b003b6cb02533bmr23146416oib.44.1701248551259; Wed, 29 Nov 2023 01:02:31 -0800 (PST) MIME-Version: 1.0 References: <6566989F.7010305@adviesenzo.nl> <34dada8e-7f2a-4d94-b7df-d9d3c7b2f3ce@app.fastmail.com> In-Reply-To: Date: Wed, 29 Nov 2023 10:02:20 +0100 Message-ID: Cc: php internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] What is the prevailing sentiment about extract() and compact() ? From: landers.robert@gmail.com (Robert Landers) Robert Landers Software Engineer Utrecht NL On Wed, Nov 29, 2023 at 9:36=E2=80=AFAM Ayesh Karunaratne = wrote: > > > > > try { > > // do stuff > > } catch(Throwable $exception) { > > $this->logger->error("failed to do stuff", compact('exception')); > > throw $exception; > > } > > > > I wonder why not just create an array with the key... > > ```php > try { > // do stuff > } catch(Throwable $exception) { > $this->logger->error("failed to do stuff", ['exception' =3D> $exceptio= n])); > throw $exception; > } > ``` > > It's a few more characters of course, but I would pick the readability > and simplicity over the potential typos (which the IDE should point > out) and a few key presses it saves.I Hey Ayesh, Yeah, this is very much a personal preference kind of thing. I choose compact not because it is shorter to type, but because typos are a thing if you've been around PHP for awhile... who hasn't opened a function written 15 years ago with a misspelled variable that you want to fix but it has been that way for 15 years, so you don't fix it. I've also used compact inside array_maps like: $arr =3D array_map(function($a) { $name =3D $a['first'] . " " . $a['last']; // more mappings return compact('name', ...); }, $arr); just because it is easier to type/read than a bunch of array accesses. Possibly faster as well, but if it is, it's by nano-seconds. Robert Landers Software Engineer Utrecht NL