Closed Nek- closed 1 year ago
@Nek-
Returning an empty string from a method that should return boolean
seems kind of risky.
Would it not be simpler to replace:
return (substr($haystack, -$length) === $needle);
With:
return (substr($haystack ?? '', -$length) === $needle);
and then doing the same null coalescing for the strtolower
call above to preserve the same functionality??
EDIT: And in the case where you want to keep PHP 5.6 compatibility you can simply use the ternary operator instead of null coalescing
Hello, I fully agree with you but it's the current behavior of the function. My fix is not designed to make any behavior change.
@Nek- if current behavior should be preserved your return should be a boolean not a string.
The line return (substr($haystack, -$length) === $needle);
always returns a boolean which also is the type specified in the docBlock.
Indeed, I don't know why I ended up with this fix. It's just wrong. Nice catch.
The doc block also specifies that $haystack
is not nullable string so passing null should be invalid. Maybe it would be better to fix the caller to not call the method with null.
@spaze about this however I was right because it happens when running the client.
You should add phpstan or psalm.
@spaze about this however I was right because it happens when running the client.
That's correct, but I'm not talking about the bug, I've suggested maybe a more correct fix :-)
The bug indeed seems to surface when you're creating the TableRestProxy
object directly by calling its __construct()
. I'm using TableRestProxy::createTableService()
and that's working fine so that might be a workaround for you too.
You should add phpstan or psalm.
I agree that running a static analyzer would help the lib tremendously but I'm not a maintainer so I can't add anything :-)
src/Common/Internal/ServiceRestProxy.php:80
may call this function with null, the linereturn (substr($haystack, -$length) === $needle);
is an issue because PHP 8.1 deprecated the use ofsubstr
on null.