Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: preg_match(): return vualue Date: Sat, 28 Nov 2020 10:57:07 +0100 Lines: 31 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net zIPp9pvnYhU1SL8FnBcd6QKtXGF2Idl7hxqZC9vYtChvyP0Pn8 Cancel-Lock: sha1:sI7p0h7bM7S1BREE+hMWki8hddI= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.3 In-Reply-To: Content-Language: en-US-large Xref: csiph.com comp.lang.php:18430 On 28/11/2020 09.40, alex wrote: > From https://www.php.net/manual/en/function.preg-match.php > Warning  This function may return Boolean FALSE, but may also return a > non-Boolean value which evaluates to FALSE. Please read the section on > Booleans for more information. Use the === operator for testing the > return value of this function. > > That is? Put is simply you can get a result that is 0 (no result) or false (error), these two values are equal if you make a simple comparison of the values var_dump(0 == false); // => bool(true) If you need to distinguish between error and no result you need to see if the values are identical var_dump(0 === false); // => bool(false) In theory the error result could happen when you have a string that should match what you are looking for, but also include data that causes the regex to fail. See https://www.php.net/manual/en/language.operators.comparison.php for more information on comparison operators. -- //Aho