Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110448 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 58304 invoked from network); 9 Jun 2020 14:40:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Jun 2020 14:40:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D2D031804F6 for ; Tue, 9 Jun 2020 06:23:54 -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-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (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 ; Tue, 9 Jun 2020 06:23:54 -0700 (PDT) Received: by mail-lj1-f169.google.com with SMTP id 9so25028472ljc.8 for ; Tue, 09 Jun 2020 06:23:54 -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=mctOY079XLK1mFW0CVV3xaE/xUIqQc4aFqYQQgoKKWg=; b=HJc+8NsF/4vYUKerHZVuQlNaPQDiNDI9sQm4lzDwyR3DQSrJU+QLL8gjgv5BWOkr+a 7GhH7MU+rizjWkNr4buYfeErYtnXr3Hc4hiOx1EBvdPnHWxakm+3eUGzX4rydkl1jm9f pnicPqKvRIq4MHiTulyCIjJVsjLFo8I6h9luSQA8eHpqmmolSB5hku8A/QvNta5NsCJ2 ejQOWaMlwUvxmDX2gfKGo7rOCb2yW/aWU0qcNK+v7qt2plwlY28OC8qouk6yYNHjA2Kx J6nXoFMfCopdBBS+0MmS5+/Vv9LHofn4IdJaSCZ3qHUv8NUbl1lUwBU/YG5sX7tC9hfN KpZw== 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=mctOY079XLK1mFW0CVV3xaE/xUIqQc4aFqYQQgoKKWg=; b=f+a0rkM7Pj6716/UZDjuFzEY4fjoWU02Kdjnkln7gOJOOVAtvXLdhpGuF3AzwJSU5P a7b6SZOxn2FyuprqQdoUllPE6BCovEoqkjvIR+/8prdrct4lrOrNynWPdok2bGD7YbyX y6XZr6R8yDhDbvq2ABJRI/lMJm9UZ/QKoIcABacA2TLfRsATh9fEKDI1jbAmLn6tnJq7 88iHkrAyDNCP1V2t0lR09pGIzzxHjL5dciGCXxLXn1zo6o/NlAXk320mKA2RUb/c3KU0 vlSdmcnxJGqsZz2dZfOtDP4d21uAPm6V2ju3BC44E8rqB1jv8DJxDUFgDYcr5Skf+ebW TWcA== X-Gm-Message-State: AOAM531tAd/K+PooSOySaNMvpT2TkYkmF461rKGixKtAwCYLaQjTwlhm PWZXtKSXz/2k8zKTQimJCdMuszx/zCcYkEDRNGKrhZhe X-Google-Smtp-Source: ABdhPJy38HVCoSKOx3eys3c7GllKAX9WeNauvq0o3/obQhXPXCxUUt2VrGaqc67Nh+CVoBrlYFFGteketVBFLb0Q8RA= X-Received: by 2002:a2e:908f:: with SMTP id l15mr8960208ljg.307.1591709031079; Tue, 09 Jun 2020 06:23:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 9 Jun 2020 15:23:33 +0200 Message-ID: To: Sara Golemon Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000006222de05a7a6a313" Subject: Re: [PHP-DEV] Re: Making all Traversables an Iterator or IteratorAggregate From: nikita.ppv@gmail.com (Nikita Popov) --0000000000006222de05a7a6a313 Content-Type: text/plain; charset="UTF-8" On Tue, May 12, 2020 at 2:49 PM Sara Golemon wrote: > On Tue, May 12, 2020 at 3:26 AM Nikita Popov wrote: > > // WeakMap::getIterator(): Iterator > > ZEND_METHOD(WeakMap, getIterator) > > { > > if (zend_parse_parameters_none() == FAILURE) { > > return; > > } > > zend_create_internal_iterator_zval(return_value, ZEND_THIS); > > } > > > Given that the body of this method seems to usually (always?) be the same, > why not define it in InternalIterator and allow it to be inherited? > > > There's some bikeshed potential here regarding the class name. > > > Not personally over-picky, but I do agree that "Internal*" is a bit > awkward. Unfortunately there's not much that's better and appropriate for > exposing to scripts. This might be one of those rare occasions where > exposing "Zend" into userspace makes sense. "PHP" is overloaded into > several meanings that are significant for userspace developers, but > something like "ZendIterator" might convey the right level of "This has to > do with the engine, please move along". Or maybe go verbose: > 'IteratorForExtensionClassImplementations'. :p > > > ZEND_ASSERT(scope->get_iterator != zend_user_it_get_new_iterator); > > Does this mean that if I do `class Foo implements InternalIterator {}` in > a script, I can assert (crash) PHP? I don't see anything obvious (at a > glance) preventing me from inheriting from InternalIterator. > InternalIterator isn't an interface, so it's not possible to implement it in this way. It's not possible to directly construct an object either. What can happen is that the getIterator() method is replaced in a child class, but this will get picked up automatically, and the get_iterator handler will be changed to zend_user_it_get_new_iterator automatically. Nikita --0000000000006222de05a7a6a313--