Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109011 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 74760 invoked from network); 14 Mar 2020 16:31:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Mar 2020 16:31:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 348811804D8 for ; Sat, 14 Mar 2020 07:53:51 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-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,FREEMAIL_FROM,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-vs1-f54.google.com (mail-vs1-f54.google.com [209.85.217.54]) (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 ; Sat, 14 Mar 2020 07:53:50 -0700 (PDT) Received: by mail-vs1-f54.google.com with SMTP id n6so8314012vsc.3 for ; Sat, 14 Mar 2020 07:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=vc27xspbr5Fd3MHdDpouEF5b/En5zs6LpK86zce0zeg=; b=nd7JoMH/MIF45JhXzH4ZPq7qX94xrWAAYAv+z9hm6njgZnWK1tm2Wne2VVkTuTN/jz WqCbmrOJi3tu35w0Ip1++vxyQVv39jMLw+axSsUQJ7BvzCGk+Ak0UjMTTQHzyOLtvzEJ jIVvmlJ5gKhuBk3eAjgKefTwU1q8x2Gtqfh0B9FqgD28Y70GtI90cGrdA+NnkLPzeznG reazKfnz3QEcBlSG57DTqmVj+GaV+AoYhbVrUkCVRWhkboi8kCpJr0Ugu/qtC7vL8ylx +xQeuG2SNtPvYHpi0w1GW9+NEg6M0lxUJxI693v/X9t2aaqn88o8KhgP+cLAyyCngiIN gOhA== 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:from:date :message-id:subject:to:cc; bh=vc27xspbr5Fd3MHdDpouEF5b/En5zs6LpK86zce0zeg=; b=gtBZqQOgWvuMHFoSYHUte3L/Z/UnuneMXOE/LXddnmuxeHi/vZJJaqrR53dSwS/xYr y+5Wzuff94UEgtNpJcoZ2VXrWiou5MHqwo4d9Gmi7yUrAgyAJZORvgUyXDiloTvV60Bn weEf7UK2xjnPBilVnLebhseB/9i0ZTIJtEjHQNxTK9to1S2TRIlZibyxC/G0m2ND/N6Y HpW/eiV0+2Dpy1udQqMwagwAw/zwTkXUfiKBm9uNOquX/MQ3Eyu08IJSpD1YxQwxoHZu pk9Th8u/e8L/TzeaBaizjSpArzB8RsCMuvTSMKeN+F+xlJDNmbC/3VVJprafy+6vzM5f jwDg== X-Gm-Message-State: ANhLgQ2fDyIzLz0PdweKr3kbvzeL8c0RLvvjNkBZ0wtua0/eZUQBzC/Y gVRWdFrE2MZmkjkmLPnPu88m6aEMwMEG1Zwb0xU= X-Google-Smtp-Source: ADFU+vtFyBpY/0am3KXaweUXpegElnTm/hST2HXtcuFM3PuJtOSZMAoTHTr/trJL+lQDH11xDrjaF8/chombsB1FOgk= X-Received: by 2002:a67:71c3:: with SMTP id m186mr12696467vsc.6.1584197628266; Sat, 14 Mar 2020 07:53:48 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 14 Mar 2020 10:53:38 -0400 Message-ID: To: =?UTF-8?Q?Midori_Ko=C3=A7ak?= Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000e30e0e05a0d1c0c3" Subject: Re: [PHP-DEV] Associated Arrays as function parameters From: theanomaly.is@gmail.com (Sherif Ramadan) --000000000000e30e0e05a0d1c0c3 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I might be off here, but I believe the issue with that is that it's a performance problem. You would have to check each key and function parameter for a match, which would be slow. You can, however, achieve what you're after just by using an array without any packing/unpacking. function foo(Array $args) { // Expected arguments $default =3D ["name" =3D> null, "birthday" =3D> null]; // Get actual arguments $input =3D array_intersect_key($args, $default) + $default; // final if (!isset($input['name'])) { // ohnoes you forgot your name } if (!isset($input['birthday'])) { // ohnoes you forgot your birthday } // otherwise use $Input['name'] and $input['birthday'] here... } On Sat, Mar 14, 2020 at 10:43 AM Midori Ko=C3=A7ak wrot= e: > Dear Internals, > > I would like to as you a question. I know that it is possible to use an > array to function parameters like: function(...array); But this method is > not working when the array is associative. > > Would not be fine if an array like ['param1'=3D>'value', 'param2' =3D> 'v= alue'] > would be used in a function like function(param1, param2) regardless of t= he > order? > > I think it would make our lives is easier. I'd be also happy if you know = if > there is more effective method to achieve the same result. > > Thanks, > Midori > --000000000000e30e0e05a0d1c0c3--