Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105849 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 94631 invoked from network); 6 Jun 2019 14:37:55 -0000 Received: from unknown (HELO mail-wr1-f50.google.com) (209.85.221.50) by pb1.pair.com with SMTP; 6 Jun 2019 14:37:55 -0000 Received: by mail-wr1-f50.google.com with SMTP id p11so2087154wre.7 for ; Thu, 06 Jun 2019 04:49:18 -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=9QvAxZgnwKRYDVFuf9GxsViZtelSgtIb+WR7oP1LJaw=; b=tEwgblhie1pLe/7JFxQOqn27SJpW8QcqBfnhLvZjI55p8TxmAh1tMMtxJ6XxBj82zv sQQghN6STr/qDJ4RwANynV10/7PNNvfaiIMFGEgHk27RiY4HDI5AHqq9Mlz7lKCyKDSP wMbr+2IynnJ+QIghB/DGLiUs4UcZu6z2lsaVRBdmYoanTzr4NDu2aphzVn0XyzvX0b00 z+KawawXiY3kSCIIzs2qwQ0Eo63MnfUKOl1mKpBgF0q1/SwcenSZv7mSlKjzSwOCX5rY YEEwjUibACItxGvdZmPyy41Q7MkYeZbrzSvI2HegQqEY0ayl5x1TrLUWEYIvSXA1L5O8 uhyQ== 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=9QvAxZgnwKRYDVFuf9GxsViZtelSgtIb+WR7oP1LJaw=; b=F1AvqvGI6GVNIj6IQfIOS+Q3fI6oZWH/K4L8JgqTp5/7RLBXJ4oM+7RcWwuLRr96kd cZrSemBHaSKJgzRh0vVVtvlGwNJT5ej2/sFRU41U4frJ7u8V7W38wU1tlEz742PYdoE+ Pu9+bxW9p6CHfbwQpY44DzqFHyQab0l3wecspeYv8qD/CAiUlNN6JSUui6+lKdDxMpnJ tQ8+2jCnpD0LnWwiM7BkQFDh+SuFqR31VNQSNWvHvD7S6DvHZp7BLJ8qnJd5cHjX0mtY olZaHIXiHfS0TDgIuFYNwpLXwXO05p5W5z9oZtPTD19/niMgC76SnM62rxPDOMj44xdY kvTw== X-Gm-Message-State: APjAAAXqxSFAO3aNCrRSIwYNTa7PRXuzxrfyfbjb1aUzkNx6jeCruDmN 6UuQspfuTEOEZKUC4EjpNbKDTxQLNkvP3Fjyeqw= X-Google-Smtp-Source: APXvYqzjBfDysS1WCUdmcDqxYxkgvTCk55YaRvcIbb826Uq95P8hGmr+RHqyUSj3kk1qTfpKeRZEjnLnsG90JnoIDSM= X-Received: by 2002:adf:f3cc:: with SMTP id g12mr27739387wrp.149.1559821758141; Thu, 06 Jun 2019 04:49:18 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 6 Jun 2019 13:48:51 +0200 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000ce9b74058aa64d29" Subject: Re: [PHP-DEV] Handling of null arguments to internal functions From: arvids.godjuks@gmail.com (Arvids Godjuks) --000000000000ce9b74058aa64d29 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =D1=87=D1=82, 6 =D0=B8=D1=8E=D0=BD. 2019 =D0=B3. =D0=B2 10:55, Nikita Popov= : > Hi internals, > > The https://wiki.php.net/rfc/consistent_type_errors RFC resolved one of > the > big differences in argument handling between internal and userland > functions. This change allowed us to add return type information (availab= le > through reflection) to internal functions, something that Gabriel Caruso > has been working on. > > During the discussion of that RFC, Andrea raised another important > difference: User functions do not accept null for a typed argument, unles= s > it is explicitly nullable (through ?Type or a null default value). This i= s > independent of whether the type is scalar (int and array both reject null= ) > and also independent of strict_types. > > For internal functions on the other hand, in weak typing mode, null will = be > accepted to scalar arguments and coerced to the respective type. For > example strlen(null) becomes strlen('') becomes 0, without emitting any > diagnostics. > > More precisely, this is a difference between two different argument > handling approaches, arginfo (used by userland, forbids null) and zpp (us= ed > by internal, allows null). As we would like to also use arginfo for > internal functions (as it is available through reflection, while zpp is > not), we need to resolve this discrepancy in some way. > > The "correct" thing to do would be to forbid passing null to non-nullable > arguments for internal functions / zpp as well, making behavior fully > consistent. I've created https://github.com/php/php-src/pull/4227 to > prototype this and see how the test impact looks like. > > However, I think there will be a lot of fallout from this change. When > running this patch against the Symfony test suite, I get many thousands o= f > deprecation warnings (though many with the same root cause). In some case= s, > it's a matter of us not marking arguments as nullable that likely should > be, e.g. I was able to remove a slew of deprecation warnings by making th= e > $pattern argument in NumberFormatter/IntlDateFormatter nullable. > > This is what I originally wanted to propose here, but after seeing the > impact this has (relative to, say, changing =3D=3D semantics) it might no= t be a > good idea. > > If we don't want to do that, then we should start accepting null for > scalars for internal functions in arginfo as well. It will resolve the > arginfo/zpp discrepancy, but will leave the divide between > internal/userland functions. > > Thoughts? > > Regards, > Nikita > Hello Nikita, as a user-land dev and in general looking at where I would like for PHP to end up long-term, I think the first one is a better solution, though quite a bit more painful to do and longer-term to implement due to the amount of work involved. My reasoning is JIT - as things go forward, we probably are going to start to see some things get implemented in PHP instead of the C core (*caught* PDO) and that might lead to some strange situations if the argument handling is going to be inconsistent between these two worlds. But consistency, in general, would be a nice change of pace so you don't have to keep in mind that there are slight differences in behaviour depending on what you call - a built-in function or a userland one. My 0.02$, Thanks. --=20 Arv=C4=ABds Godjuks +371 26 851 664 arvids.godjuks@gmail.com Skype: psihius Telegram: @psihius https://t.me/psihius --000000000000ce9b74058aa64d29--