Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError when substr return FALSE #929

Merged
merged 1 commit into from
Apr 15, 2021

Conversation

XOlegator
Copy link
Contributor

There is type error on PHP 7.2.32:

Fatal error: Uncaught TypeError: trim() expects parameter 1 to be string, boolean given in /home/webmaster/data/www/vendor/zircote/swagger-php/src/Context.php:212 Stack trace: #0 /home/webmaster/data/www/vendor/zircote/swagger-php/src/Context.php(212): trim(false) #1 /home/webmaster/data/www/vendor/zircote/swagger-php/src/Processors/AugmentOperations.php(26): OpenApi\Context->phpdocDescription() #2 /home/webmaster/data/www/vendor/zircote/swagger-php/src/Analysis.php(466): OpenApi\Processors\AugmentOperations->__invoke(Object(OpenApi\Analysis)) #3 /home/webmaster/data/www/vendor/zircote/swagger-php/src/functions.php(57): OpenApi\Analysis->process(Array) #4 /home/webmaster/data/www/stolplit.ru/mobile_api/generate_doc.php(27): OpenApi\scan('/home/webmaster...') #5 {main} thrown in /home/webmaster/data/www/vendor/zircote/swagger-php/src/Context.php on line 212

This little patch fixes this issue

@DerManoMann
Copy link
Collaborator

Thanks for the PR.

Before merging, could you perhaps provide a simple example of how this can happen?

Also, is this only an issue with PHP 7.2.32 or is that just the version you happened to be using?

@XOlegator
Copy link
Contributor Author

I looked under the debugger, in what place and with what values the script crashes in this place.
PHP 7.2 with mbstring.func_overload=2

$summary = 'Получение токена авторизации и данных пользователя';
$sameString = 'Получение токена авторизации и данных пользователя';
$res1 = substr($sameString, strlen($summary));
var_dump($res1); // <--- bool(false)

PHP 7.4 with mbstring.func_overload=2

$summary = 'Получение токена авторизации и данных пользователя';
$sameString = 'Получение токена авторизации и данных пользователя';
$res1 = substr($sameString, strlen($summary));
var_dump($res1); // <--- string(0) ""

So, return value of function substr() was changed in PHP ¯_(ツ)_/¯

@DerManoMann DerManoMann merged commit e62ff09 into zircote:master Apr 15, 2021
@DerManoMann
Copy link
Collaborator

Thanks @XOlegator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants