Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112353 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 11436 invoked from network); 1 Dec 2020 20:22:48 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 1 Dec 2020 20:22:48 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4C44D1804D4 for ; Tue, 1 Dec 2020 11:50:17 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.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 ; Tue, 1 Dec 2020 11:50:16 -0800 (PST) Received: by mail-pl1-f178.google.com with SMTP id s2so1741770plr.9 for ; Tue, 01 Dec 2020 11:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:references:from:subject:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=z2iIVK3iSRTp8iYBWaFA45UrjQi9k48TKeEhIYYdLoI=; b=DxoxUa9PEwMCHm4lIL7FLhkSHs+1wBql+gdEE5nut2rwGCsyfA0X4kZ2ItIdOlR01R NR2/gAGRORamU8i9WUgOmSLMcV17eEMcgmWpGhQ5COSXJjf5Tb5Ya93xjKY2OZySLcGf NRQzwAkGgTeSZ07WtUYDZUL6G54tn0VlB1jICyPB7gmP/u8aJHcibwccMuz4NRkD8ZtZ 0zqzssyaBsAOjRlsFE5ZTurvlkGLqrJRfqJhx5zL0SXQuV9W9J9IAaxyCUbhglOq07x+ iKnIWRIqYB6XBTEFFE3Np5y2GSfNN5KzObHHcJEZ5CoNf4m9LL49Fu14HTIA63Why74m nEfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:references:from:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=z2iIVK3iSRTp8iYBWaFA45UrjQi9k48TKeEhIYYdLoI=; b=j9bIc6K/zomfxJk6bpFQn7sjImKJmTl4+C/627W+4pM/N+fyECUWIjbIHHRYJ1rDI1 81aoCS+kbrvetY9UVFIgvefTPIFObwZa1uTmaElZkzboD7hvjNxG1oKQHKFwdYa+hR76 aagGhfMRLB14lwyN7rxM1YWXWqhAs1v5hafJvDnrPXVfHCij6LhREbUNleO/qc/qoDX0 avkmQrcdtyu0QZnzFvP0YA8p2UbWNP0OVt1uk0hEzv8V1MNu48pEdF1g9uo7xjxqeHlg 0R14P4fmRmosTu1yUgg/yHB0P0ec0sux/Bl09POSn2PSgTbBLPHRH4GkdogohnnfyROM h2qw== X-Gm-Message-State: AOAM532AW8pXPDVRO6fcItw0PDRuB3/uxrLnQmYVHCn6HQlr/GLCYTiL 2a+55Lrdp6lCxyixnHdcVXtHd23qzPnN X-Google-Smtp-Source: ABdhPJxP1R1aLCydlxeX8LnpA9gBsO1uemBQoHQZ7mtJxA6dGHJY7gps9lT5v6X/383KO0gwF48V0Q== X-Received: by 2002:a17:902:b983:b029:da:8c9a:6ac6 with SMTP id i3-20020a170902b983b02900da8c9a6ac6mr4321872pls.54.1606852215102; Tue, 01 Dec 2020 11:50:15 -0800 (PST) Received: from Stas-Mac-3.local (ec2-44-226-106-152.us-west-2.compute.amazonaws.com. [44.226.106.152]) by smtp.gmail.com with ESMTPSA id q20sm403594pgb.6.2020.12.01.11.50.14 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2020 11:50:14 -0800 (PST) To: internals@lists.php.net References: Message-ID: Date: Tue, 1 Dec 2020 11:50:13 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] PHP 8 is_file/is_dir input handling From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > In PHP 7, this returns FALSE: > > php -r 'var_dump(is_file("ab\0c"));' > > In PHP 8, the same code throws a ValueException. Problem is now that I think this is a mistake. Exceptions should not be thrown on such values, it only breeds boilerplate code (now you'd have to wrap each call to is_* into try/catch or add another pre-call validator just to ensure it doesn't throw). PHP type system is not robust enough to support fine-grained types like "string that has certain format", and pretending we do have this as a type and throwing typing error on it only makes the consumer work harder for no additional gain. In almost every situation I can imagine, string that is not the name of the file is equivalent to string that is not the name of the file and also has \0 in it. However, this setup forces me to treat them differently and add additional validation step to it. While to some functions it may be a useful functionality - specifically to constructor functions expected to return an object, so they can't really tell "you gave me invalid data" other than throwing - for something like is_file it will only be annoying. -- Stas Malyshev smalyshev@gmail.com