Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84019 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91722 invoked from network); 27 Feb 2015 15:31:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2015 15:31:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.169 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 209.85.217.169 mail-lb0-f169.google.com Received: from [209.85.217.169] ([209.85.217.169:45246] helo=mail-lb0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 69/66-32582-BBD80F45 for ; Fri, 27 Feb 2015 10:31:08 -0500 Received: by lbjb6 with SMTP id b6so17967956lbj.12 for ; Fri, 27 Feb 2015 07:31:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ZBzSRjsTUla/9529Kbmw/134jN1R8LVzwN+cb2uZxPc=; b=OZDxPEPPUvn0pd19hRYZGq0qt6ETQFKkubuNfUqkEZfnaAehHQRxOQGhsqFDBHEOuq dvqtvF4Kwi0jC2AoqlV+Tnqcgsi5X1PsfQ01ABd4HFhV3m3yovX6HolaeuZgD2e1Z+fH GphiAQDfasMO/RUJ18zui/7lSM6nP+PU4VMLwjL624ATp5retKJefnGe5YQX2AdQgiE/ 0iAs1LHD/JzFw75Ro8hpvc+KMbsd9PUsnNm67bBBp13956rVsJP1Q3JslPJxxo3a586v OCPyQ5t8ftMqhxIExl840dsxkwijx59z+J6gHJlUqF2vOUNdJlsFwRa6Ljl6lf39E2uo qFqQ== MIME-Version: 1.0 X-Received: by 10.152.28.73 with SMTP id z9mr13179063lag.28.1425051063727; Fri, 27 Feb 2015 07:31:03 -0800 (PST) Received: by 10.25.43.9 with HTTP; Fri, 27 Feb 2015 07:31:03 -0800 (PST) In-Reply-To: <4ED7146272E04A47B986ED49E771E347D3111ACD63@Ikarus.ameusgmbh.intern> References: <4ED7146272E04A47B986ED49E771E347D3111ACD63@Ikarus.ameusgmbh.intern> Date: Fri, 27 Feb 2015 10:31:03 -0500 Message-ID: To: Christian Stoller Cc: Damien Tournoud , Zeev Suraski , PHP internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Coercive STH - some real world tests and updated RFC From: ircmaxell@gmail.com (Anthony Ferrara) Cristian, >> All those are due to a bug in substr(), that we see now only thanks to >> proper type identification. There is no reason for substr() to ever return >> a boolean. It really needs to be fix to always return a string. >> >> Damien > > It is not a bug. FALSE as a return value of substr() is the identificator > for an error (e.g. invalid arguments), as it is stated in the documentation: > > "Returns the extracted part of string; or FALSE on failure, or an > empty string." [1] > > This is an example which shows, that Zeevs RFC helps to find bugs in > applications. Because here are given invalid arguments to the method. In > other languages for example Java, you'll get an IndexOutOfBoundsException [2] > if you are trying the same ;-) Well, it depends on your definition of bug. If you look at PHPUnit's TestSuite::isTestMethod method, you'll see this: $doc_comment = $method->getDocComment(); return strpos($doc_comment, '@test') !== false || strpos($doc_comment, '@scenario') !== false; Now, with the coercive mode (and my strict mode), that will error if the method does not have a docblock. The reason is that `$method->getDocComment()` returns false if one does not exist. Is that a bug? Well, semantically, maybe. But from the application level, no. Passing the boolean result to `strpos` directly ensures that the result will be `bool(false)`. So the overall method behaves as expected returning true in the correct context (it's a test method) and false in incorrect contexts (it's not). So did the coercive mode find a bug? Not really. It found something that may have worked in a way you didn't expect it to, but it wasn't a bug (at least to the application). Now, if you care about types and type changes, then yes, that is a bug. And that's why the dual-mode RFC gives you the choice. You can choose to care about types or not. Not some weird hybrid where you have to care even if the code is practically correct... Anthony