Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121844 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 68660 invoked from network); 29 Nov 2023 01:59:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 29 Nov 2023 01:59:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8B4CC180031 for ; Tue, 28 Nov 2023 18:00:03 -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=4.5 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_SOFTFAIL,STOX_BOUND_090909_B autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from shrimp.cherry.relay.mailchannels.net (shrimp.cherry.relay.mailchannels.net [23.83.223.164]) (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 ; Tue, 28 Nov 2023 18:00:02 -0800 (PST) X-Sender-Id: a2hosting|x-authuser|juliette@adviesenzo.nl Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 6B0646C2D4A for ; Wed, 29 Nov 2023 01:49:37 +0000 (UTC) Received: from nl1-ss105.a2hosting.com (unknown [127.0.0.6]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id 30A926C2DA7 for ; Wed, 29 Nov 2023 01:49:36 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1701222576; a=rsa-sha256; cv=none; b=2oY4+bYTM+O6XHDC+bTgi2Y0/laVtA+lBxcCqUZHiamCYY4aVO5vbANpoSYB6ImYuTV5z6 VeQEwluasATf4q1rRONAGVUnal8Ir9EFpqEDkMnwmPaQn3JWSWDOfUh2z8+HxzsFI3+a0T Dp+E7VTgVVcMim/Chi1pn9fXpMxo25Vchazzu8Dq+RckOqhfNtqP7ByqfXMVyOw4NpVOee 15nVdb6E8N6ZdQKcwOk5aEi2p77xpPYLTb+A2heqmDDdpIVn+zltZXTRru1PIvpI426FfA dMTyFAb1mfRGuZbkNBSroXhnx3nMzaQ76KyjruzbFJIkU0ae0tYuWiCx2ERcWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1701222576; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: dkim-signature; bh=sE/Jktce0R4I/oxjxkm5i+xw6t0r4jXUJPYpL97+wdo=; b=qaoSu1eDrkRALnlL8lcbILgkGTM0dw3BrY2P9CnHKsPNrigYMegr1dEDkNgf9EAmC0DyfW L7JqzJ9NPoXbosLBWQ8ldjPwpCrOusJrieATiBYG1zABaLRJ045KA6fNJX2JDKalXIaFdW B5kBtY8ZwBplSn9akKXk/z3rDrVJkTvkmRa0JkU0eoRFSNaPbA5oGwxCuIzVEbo3v3fR5q kgLPLn1XB7qvCzY+lBwk1O9ZPwMjAnOGo00s4nRbkToHmUo+5FA/IOc/zFWlf9RXvDx7eE 3arBPMquzSJr2FB0NRQN9hOZ+o4H2yomVBXCg/OewjsoPKXsoJ1L3vRI1uAQRA== ARC-Authentication-Results: i=1; rspamd-696ff67dc8-qkxq8; auth=pass smtp.auth=a2hosting smtp.mailfrom=php-internals_nospam@adviesenzo.nl X-Sender-Id: a2hosting|x-authuser|juliette@adviesenzo.nl X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|juliette@adviesenzo.nl X-MailChannels-Auth-Id: a2hosting X-Eyes-White: 76422ea153147748_1701222576609_3110400440 X-MC-Loop-Signature: 1701222576609:2699960141 X-MC-Ingress-Time: 1701222576608 Received: from nl1-ss105.a2hosting.com (nl1-ss105.a2hosting.com [85.187.142.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.105.117.157 (trex/6.9.2); Wed, 29 Nov 2023 01:49:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=adviesenzo.nl; s=default; h=Content-Type:MIME-Version:Date:Message-ID: Subject:From:To:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=sE/Jktce0R4I/oxjxkm5i+xw6t0r4jXUJPYpL97+wdo=; b=IdVnNpvPY7u4pcdoMmDB0sZpbe bt5lX7q1WAS6sGkNrAW+EtSPl3iWXO01y4cRvU7nq40tf4WMlxYPGnO9P0QoBSo9BAOViu8ET/YBw sAQlY65Hi7N18RA3TLsU82G/0+EOKj+8PsHEw30f3cTc/AYvhcwiKmM5AfnSgB0O5n88=; Received: from 86-154-178-143.ftth.glasoperator.nl ([143.178.154.86]:50435 helo=[192.168.1.16]) by nl1-ss105.a2hosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96.2) (envelope-from ) id 1r89hm-009zC0-3C for internals@lists.php.net; Wed, 29 Nov 2023 02:49:34 +0100 To: "internals@lists.php.net >> PHP internals" Message-ID: <6566989F.7010305@adviesenzo.nl> Date: Wed, 29 Nov 2023 02:49:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------010801020309000409010008" X-AuthUser: juliette@adviesenzo.nl Subject: What is the prevailing sentiment about extract() and compact() ? From: php-internals_nospam@adviesenzo.nl (Juliette Reinders Folmer) --------------010801020309000409010008 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit L.S., What with all the drives towards cleaner code, how do people feel nowadays about `extract()` and `compact()` still being supported ? Both have alternatives. The alternatives may be a little more cumbersome to type, but also make the code more descriptive, lessens the risk of variable name collisions (though this can be handled via the $flags in extract), prevents surprises when a non-associative key would be included in an array and lessens security risks when used on untrusted data function foo() { $array = [ 'color' => 'blue', 'size' => 'medium', ]; // Using extract. extract($array); var_dump($color); // Not using extract. var_dump($array['color']); $color = $array['color']; var_dump($color); } function bar( $color, $size ) { // Using compact. $array = compact('color', 'size'); var_dump($array); // Not using compact. $array = [ 'color' => $color, 'size' => $size, ]; var_dump($array); $array = []; foreach (['color', 'size'] as $name) { if (isset($$name)) { $array[$name] = $$name; } } var_dump($array); } https://3v4l.org/JeHnY I can imagine these could be candidates for deprecation ? Or limited deprecation - only when used in the global namespace ? For now, I'm just wondering how people feel about these functions. Smile, Juliette --------------010801020309000409010008--