Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:122002 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 60366 invoked from network); 14 Dec 2023 10:39:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 14 Dec 2023 10:39:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 746F318004E for ; Thu, 14 Dec 2023 02:39:48 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-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,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from smtp46.i.mail.ru (smtp46.i.mail.ru [95.163.41.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 14 Dec 2023 02:39:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mail.ru; s=mail4; h=Content-Transfer-Encoding:Content-Type:To:Subject:From: MIME-Version:Date:Message-ID:From:Sender:Reply-To:To:Cc:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive:X-Cloud-Ids:Disposition-Notification-To; bh=Nqdq5wjJEg+S7zoZA3gQa1fv5nIc++H6IHXh+gwIPBw=; t=1702550370; x=1702640370; b=BECFYZDXP+8b1jsQto863EpReU7NFmMXf1wjOv0suMN0foLqaiFJz1wbf+nHvI6KHYbby9XL7As LJLeA6zcZDEAMEnTzEtENs23j7su/11oynNiR7darykbM/skGRgLd9z/sX6zz8mVF+VR4kZmODbUC Am4+tz7tbDbBkpnf5M0jC4iNQKWr0NcbJ2SAKXhCCv3td2GMauVVh2apDs5J+pM+KDYWt0GeMKEhF +/C/i6e9VptWr71kBhxX37eh8lSDu0XvC/zS7CSQwCuV77bCvBheAHZDRtzZ5c4Kua4nLRECqr53U MP7Xd+JHw/BugegB5Hu9Wc+eNle2Cl+2H58Q==; Received: by smtp46.i.mail.ru with esmtpa (envelope-from ) id 1rDj7n-001ZTc-2B for internals@lists.php.net; Thu, 14 Dec 2023 13:39:28 +0300 Message-ID: <95b03bd5-08c5-4fec-b33e-6a617e55a74e@mail.ru> Date: Thu, 14 Dec 2023 13:39:27 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: "petrov.boris.v@mail.ru" To: internals@lists.php.net Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: smtp46.i.mail.ru; auth=pass smtp.auth=petrov.boris.v@mail.ru smtp.mailfrom=petrov.boris.v@mail.ru X-Mailru-Src: smtp X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD97533543916A0F71A7F5FD72A6F01437A2062B641662DAC10CD62213F67905E7A5B99E5F4022B065184E8E08D1A6E4F24752A936FEF0FB08EDA9381C6EE66F9EA X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE712EB008F780777E9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F79006372A1456D053D20C618638F802B75D45FF36EB9D2243A4F8B5A6FCA7DBDB1FC311F39EFFDF887939037866D6147AF826D86627FF4A96492387843A23C8E08173846F9789CCF6C18C3F8528715B7D10C86878DA827A17800CE722C7672CDBCC22789FA2833FD35BB23D9E625A9149C048EEC24E1E72F37C03A0CB629EEF1311BF91D2E47CDBA5A96583BD4B6F7A4D31EC0BC014FD901B82EE079FA2833FD35BB23D27C277FBC8AE2E8B9232F411B4B10923A471835C12D1D977C4224003CC836476EB9C4185024447017B076A6E789B0E975F5C1EE8F4F765FC7CAC66D8BE5E0CF13AA81AA40904B5D9CF19DD082D7633A0C84D3B47A649675F3AA81AA40904B5D98AA50765F7900637A9ED51A6BE4EB3D4D81D268191BDAD3D3666184CF4C3C14F3FC91FA280E0CE3D1A620F70A64A45A98AA50765F7900637A2A43CD5061A88E86D1867E19FE1407978DA827A17800CE773BC869C69ECC1572DBA43225CD8A89F06BBCC99EAFD4D725E1C53F199C2BB95B5C8C57E37DE458BEDA766A37F9254B7 X-C1DE0DAB: 0D63561A33F958A58F770031018826D4403E4288D642141DE59739D49F5063FFF87CCE6106E1FC07E67D4AC08A07B9B0735DFC8FA7AC12079C5DF10A05D560A950611B66E3DA6D700B0A020F03D25A0997E3FB2386030E77 X-C8649E89: 1C3962B70DF3F0ADBF74143AD284FC7177DD89D51EBB7742DC8270968E61249B1004E42C50DC4CA955A7F0CF078B5EC49A30900B95165D34023CA4E4726A7D6C94501BB0AC7221B1EF4D7886EDDB9FD855D0E1BFD37FE0E706C4A5A51ED427091D7E09C32AA3244C4D78E7069AD57567AED0977299E739BD795D98D676DD64D0BC4AF6B5DE6957CB5DA084F8E80FEBD3F550A4CB296D7273E72ADBA9963FE16024A389F0E278DBF4 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojtsCAqtdyux0RnJS1U1g71w== X-Mailru-Sender: E5F66E47D5FC5CB6CBC00B38458C1C8E03EBF17A6E28E67A3734E22CE792EC66AF91F2C3853A33E905C6BA5951380794458BE86BBD49CEE85D6E686390B69A28205BCFCF63A2AC7969550EA701C374F82D063C67CFD4E84967EA787935ED9F1B X-Mras: Ok Subject: Are warnings guaranteed? From: internals@lists.php.net ("petrov.boris.v.mail.ru via internals") Hi. I have a question: Is there a formal rule in PHP standard library that any function which returns false as a mean to signify a failure does also issue a warning? In many codebases warnings are converted to an exception by means of set_error_handler(). Example 1 ------------------------------------------------------------------ set_error_handler(fn($_, $s) => throw new \RuntimeException($s)); if (false === mkdir('/doesn/t/exist/dir')) {     throw new \RuntimeException("can't mkdir"); } ------------------------------------------------------------------ The above code confuses a reader with issues 1) isn't the only possible return value is now true? 2) if it throws on failure, then how can it return anything? One may say the checking for false return value is redundant and the above version can be simplified based on premise that mkdir() emits warning in _all_ cases where it is about to return false. Example 2 ------------------------------------------------------------------ set_error_handler(fn($_, $s) => throw new \RuntimeException($s)); mkdir('/doesn/t/exist/dir'); ------------------------------------------------------------------ But there is also a possibility that a built-in function fails, returns false but doesn't issue any warning, therefore the handler set with set_error_handler() doesn't get called and execution continues erroneously contrary to the programmer intend of it being halted. Looking at mkdir() documentation I can't find the language supporting assumption made in Example 2. The page lists two cases for which warnings are raised: "directory already exists" and "relevant permissions prevent creating the directory". Does it mean that in case of "No such file or directory" the function would return false without raising a warning? It is possible as documentation never stated mkdir() would emit warning on _any_ failure, just return false. One may add a unit-test against mkdir() to the one's project codebase proving that "Warning: mkdir(): No such file or directory" is raised too, despite not being listed in documentation.  So far we have three cases covered. But obviously this doesn't prove that a warning would be raised for all failures, thus doesn't allow us to deem Example 2 correct and replace Example 1 with it. Is relying on warnings being converted to exceptions by error handler is equivalent to checking return value with regards to the set of error conditions covered? If this guarantee is already there, please point to me to the relevant documentation page.