Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112903 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 37572 invoked from network); 15 Jan 2021 17:36:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Jan 2021 17:36:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AD6ED1804F3 for ; Fri, 15 Jan 2021 09:15:28 -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=-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-Virus: No X-Envelope-From: Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) (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 ; Fri, 15 Jan 2021 09:15:28 -0800 (PST) Received: by mail-lf1-f47.google.com with SMTP id v24so7552376lfr.7 for ; Fri, 15 Jan 2021 09:15:28 -0800 (PST) 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=HFKWei3HCIUH2eq8m60grPkDVgEPjCbT65nJRFq/fKA=; b=UzMAtT25ykZexJ0rHhRSJH0w9Fc7MlMqijn16dWjDg5r1tgjDu1IjygOs9QLZLiiNL bBM35c8Ake3e0U1hh+oUOlV12QIi+U+E1LK1tCXFaOCu6W7CI0N7+hdqIPpN8Sn6FEX8 6uAsP/p8GuBQmZZVxrXGspDaDknpM3+E4y/MyDo4RadC1CTV9FuLsuKztQxIVR9OibXp ywXDdzi6aY3nQqUONKv4m7v5XOPBCJn/EpRAqlr7ptWe+Y+tjGEbag8atFsHnjU1DjnO tc9fBn/5Ij181sjiuNgkPv4COzxYT7TcJXi2rdH4+dh2FBDxFi4JREpwOZ4b4YlPVBBT G6Bw== 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=HFKWei3HCIUH2eq8m60grPkDVgEPjCbT65nJRFq/fKA=; b=e0NKC0soppInNLncUZB2Ng/LfcN6oD/ZqhLwBb+qTbOrBD2xEtMvgPAlhqrAf/nB7t 4FepvBhESmOnGXzKBmLdKR4U7EkGuq0Lr+3pLcaNfenH+NgUXLQ7fYDk7eFTy0yYtLNE ad+lkjE/nfBHUcKRH+zxVsQxBIstUpS4iTiZ+zlOm0A88asDulP0bPHvCNofzAXMEeDH kPGlIf/KfrVO1qKwvm/slysaMXzr7sBjgcT6Ec9JBnEo5k+n9EfhSRkt1ECXbjVEIP45 IXPsOeHtLslPlLJre/M/uZqVDnnN4fc5d72INud4KCKlk5ki2A5usN/kwTkxfwaL1VxM Zm0w== X-Gm-Message-State: AOAM532ZIwLYux5Amj0ZTt+RSAk5jAanNQ0e8Tv1Dg/3C5pNd1+sEgL6 M7i9I8CwkvIbwta+r6/UpB9Vc0qgUZ448xsKYoMveMV62atR8HT/ X-Google-Smtp-Source: ABdhPJwa+U+2tgOqo76tZmV6R7VhF1srWy2OPdvhUGZesrfAX305HKipZrRu80vRW0/ezzya4P3jG/OCMvRX7mvzPYE= X-Received: by 2002:a19:2d0a:: with SMTP id k10mr6344670lfj.286.1610730924021; Fri, 15 Jan 2021 09:15:24 -0800 (PST) MIME-Version: 1.0 References: <90e4acaa-899d-9a20-1653-f58a2a04aeb6@colannino.dev> In-Reply-To: <90e4acaa-899d-9a20-1653-f58a2a04aeb6@colannino.dev> Date: Fri, 15 Jan 2021 18:15:08 +0100 Message-ID: To: composer@colannino.dev Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000008e1ae405b8f384a9" Subject: Re: [PHP-DEV] Arg info / zpp mismatch on PHP 8.0 From: nikita.ppv@gmail.com (Nikita Popov) --0000000000008e1ae405b8f384a9 Content-Type: text/plain; charset="UTF-8" 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 ); Regards, Nikita --0000000000008e1ae405b8f384a9--