Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112907 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 46784 invoked from network); 15 Jan 2021 18:50:56 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jan 2021 18:50:56 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 393751804DC for ; Fri, 15 Jan 2021 10:29:41 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,BODY_8BITS, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from web138.dnchosting.com (web138.dnchosting.com [104.171.28.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 15 Jan 2021 10:29:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=colannino.dev; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:To:Subject:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=S9Q5XKd6lhJT9xY7H9dHY24s+o1+ZFXyTaa1OWumbjs=; b=aKJHAW8vB1fymkMmO61DUloDut +HqLPbdlKhH6MFMidCOqY4d7wmoadqhSPG4atpC3DjmXlxqWN8H3o9lXRqDhZu/NCyNmGGXlhcszh U88QjxAyjATH7VRLe/5g57wZFLUHU9bKiJfeJH9aWC7FpWU+Th0aNEoAxpbpN7pjMnGyOzA3mvKB7 0/zuhkEo12i8hZCUxCbryMhg6UZh/DmZ1dQufZVWvm/oAflniwVrwTw6jSEAGlgKS8GQ+3J/u9aA2 F1NadftGZQ1kPVqTtyzMlsebfrKmJ/MutBkchMFeA0KI1lXO9d4+ijJpOYNeH46xV9BkBbrOR2kUb G6cifG4w==; Received: from cpe-23-243-43-243.socal.res.rr.com ([23.243.43.243]:55216 helo=[192.168.0.12]) by web138.dnchosting.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1l0Tqm-0000B4-Uu for internals@lists.php.net; Fri, 15 Jan 2021 18:29:39 +0000 To: internals@lists.php.net References: <90e4acaa-899d-9a20-1653-f58a2a04aeb6@colannino.dev> <76a97cce-8707-48aa-763b-20970eaa18db@gmx.de> Message-ID: <0c2d7dc8-47d0-a5a9-e772-5378226ce820@colannino.dev> Date: Fri, 15 Jan 2021 10:29:32 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <76a97cce-8707-48aa-763b-20970eaa18db@gmx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-OutGoing-Spam-Status: No, score=-0.5 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - web138.dnchosting.com X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - colannino.dev X-Get-Message-Sender-Via: web138.dnchosting.com: authenticated_id: james@colannino.dev X-Authenticated-Sender: web138.dnchosting.com: james@colannino.dev X-Source: X-Source-Args: X-Source-Dir: X-From-Rewrite: unmodified, there is a forwarder that points to the actual sender. Subject: Re: [PHP-DEV] Arg info / zpp mismatch on PHP 8.0 From: composer@colannino.dev (James Colannino) On 1/15/21 10:17 AM, Christoph M. Becker wrote: > On 15.01.2021 at 18:40, James Colannino wrote: > >> On 1/15/21 9:20 AM, James Colannino wrote: >>> On 1/15/21 9:15 AM, Nikita Popov wrote: >>>> On Fri, Jan 15, 2021 at 6:11 PM James Colannino >>>> wrote: >>>> >>>>> I have the following method defined in a PHP 8 extension: >>>>> >>>>> ZEND_BEGIN_ARG_INFO(arginfoCtor, 0) >>>>>       ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) >>>>>       ZEND_ARG_TYPE_INFO(0, port, IS_LONG, 1) >>>>> ZEND_END_ARG_INFO() >>>>> >>>>> PHP_METHOD(Trogdord, __construct) { >>>>> >>>>>       trogdordObject *objWrapper = >>>>> ZOBJ_TO_TROGDORD(Z_OBJ_P(getThis())); >>>>> >>>>>       char *hostname; >>>>>       size_t hostnameLength; >>>>>       long port = TROGDORD_DEFAULT_PORT; >>>>> >>>>>       zend_parse_parameters_throw( >>>>>           ZEND_NUM_ARGS(), >>>>>           "s|l", >>>>>           &hostname, >>>>>           &hostnameLength, >>>>>           &port >>>>>       ); >>>>> >>>>>       ... >>>>> } >>>>> >>>>> This works fine on PHP 7, but on PHP 8, I get an "Arg info / zpp >>>>> mismatch" error. I discovered that if I comment out >>>>> "ZEND_ARG_TYPE_INFO(0, port, IS_LONG, 1)", it works, but I'd like to >>>>> type hint that second optional argument if possible. Maybe I was always >>>>> doing this the wrong way, but I thought that the last argument 1 to >>>>> allow null was the proper way to handle this and I'm not sure why it >>>>> results in an error now. >>>>> >>>>> Can anyone tell me the correct way to approach this in PHP 8? Thank >>>>> you! >>>>> >>>> Your arginfo declares the arugment as nullable, but your zpp call >>>> does not. >>>> Thus the error. You need: >>>> >>>>       zend_bool port_is_null = 1; >>>>       zend_parse_parameters_throw( >>>>           ZEND_NUM_ARGS(), >>>>           "s|l!", // ! means nullable >>>>           &hostname, >>>>           &hostnameLength, >>>>           &port, >>>>           &port_is_null // Whether null was actually passed >>>>       ); >>> >>> I tried that, but I still get the "Arginfo / zpp mismatch during call" >>> error. >> >> This is the code I have now, which is still giving me the error on PHP 8: >> >> ZEND_BEGIN_ARG_INFO(arginfoCtor, 0) > You need to tell arginfo about the optional parameter: > > ZEND_BEGIN_ARG_INFO_EX(arginfoCtor, 0, 0, 1) > > However, it is much simpler to write a stub file, and to let > build/gen_stub.php generate the arginfo for you. See e.g. > . > >>     ZEND_ARG_TYPE_INFO(0, hostname, IS_STRING, 0) >>     ZEND_ARG_TYPE_INFO(0, port, IS_LONG, 1) >> ZEND_END_ARG_INFO() >> >> PHP_METHOD(Trogdord, __construct) { >> >>     trogdordObject *objWrapper = ZOBJ_TO_TROGDORD(Z_OBJ_P(getThis())); >> >>     char *hostname; >>     size_t hostnameLength; >> >>     long port = TROGDORD_DEFAULT_PORT; >>     zend_bool portIsNull = 1; >> >>     zend_parse_parameters_throw( >>         ZEND_NUM_ARGS(), >>         "s|l!", >>         &hostname, >>         &hostnameLength, >>         &port, >>         &portIsNull >>     ); >> >>     ... >> } Ahh, okay. That fixed it. Also, I didn't know about build/gen_stub.php. That will help me out a lot in the future. Thank you!