Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114623 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11616 invoked from network); 26 May 2021 18:23:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 26 May 2021 18:23:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A2D181804F3 for ; Wed, 26 May 2021 11:34:57 -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=3.2 required=5.0 tests=BAYES_20, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) (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, 26 May 2021 11:34:57 -0700 (PDT) Received: by mail-lj1-f178.google.com with SMTP id e2so2962857ljk.4 for ; Wed, 26 May 2021 11:34:57 -0700 (PDT) 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=eI/1655wAn1TyT2yJdTZVxiU/bwbfjH0fXuUMqPla54=; b=P/YVIu2RJy7HxT/LrpjVlMEuEnPwY97YScqYyNnJdmu6GttQbjPi8ioqlcFFScBxf3 xtBdcVl6YG2Phwq2LDGmgjMoe5RZGByuQh1n6FVmqOZOHGiMMN1zGzJlwDoSXUy0pAu7 qDv8sqZOhp0/sqzyzB/PnUHOkrEUow/SBoWKkP4mgVKtJtbY3RBCcGmjlJzsP4n6zXy/ oyKi1MM6yUznTMM0X9KntxrlLOy5O5m8u+jV8/+tspjsh+Mdw+ABfR4DscEcadOBG2mD Ywd+gCrsOOg6mHLCABM9svze1LMUF/c00lZdQKq1uMk1G0ecBl9KSuCv6ltecLQM8MIc wn8w== X-Gm-Message-State: AOAM5332x2EZ5PZigVM/yE11GHDkhqLmdzBMewxyKFkBRoUes5t3bmJs Z7ZrRSoZuUt2hGG8IV8MYVLFWstUmshSlSkeCMUlnOntTT+3QA== X-Google-Smtp-Source: ABdhPJywgriiV/hUxGkwMG3uyFS+rGG0fXT/nYEMBCL2bk1qtNT0ExMq9zUgOEAh4XrUQ59PDmpOSNubRNBmwkaOiGY= X-Received: by 2002:a2e:7f16:: with SMTP id a22mr3377543ljd.360.1622054095243; Wed, 26 May 2021 11:34:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 26 May 2021 13:34:44 -0500 Message-ID: To: Karoly Negyesi Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000275e9e05c33fe63d" Subject: Re: [PHP-DEV] A little syntactic sugar on array_* function calls? From: pollita@php.net (Sara Golemon) --000000000000275e9e05c33fe63d Content-Type: text/plain; charset="UTF-8" On Tue, May 25, 2021 at 4:20 AM Karoly Negyesi wrote: > I was wondering whether $array->map($somefunction) would be possible. I am > not a C programmer by any stretch but reading ZEND_VM_HOT_OBJ_HANDLER(112 > it seems to me it should be quite easy (famous last words) to find out if > object is an array and if so then > > 1. prepend the string array_ before the method name > 2. based on a small lookup table move the "object" to the right place -- > either first argument or second. > 3. do a function call instead of a method call. > While I don't love the specifics of the proposal, I am 100% in favor of allowing arrays to be used in an object-like fashion. What I don't like about the specific proposal is that it's just a little too magic in its function selection and argument mapping. There's also the fact that it doesn't leave room to improve specifics about the implementations of the methods. I'd much rather seen an `Array` class defined with specific methods declared on it. In many cases these will be simple trampolines to an existing function, but it gives us self-documenting stubs and room to wiggle out of poor decisions from the 1990s. Such a class would not be instantiable or inheritable, it would just exist as a lightweight ValueObject for performing the method invocations (we can make it internally instantiable using tricks like not calling a private constructor). Then some hand-wavey details about maybe returning objects which have a cast-to-array handler, mumble mumble, devil in the details... waving hands... -Sara --000000000000275e9e05c33fe63d--