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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to