-
-
Notifications
You must be signed in to change notification settings - Fork 144
[mbstring][PHP 8.4] Add mb_ucfirst
and mb_lcfirst
to polyfills
#466
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
Conversation
} | ||
|
||
try { | ||
$validEncoding = @self::mb_check_encoding('', $encoding); | ||
} catch (\ValueError $e) { | ||
throw new \ValueError(sprintf('mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); | ||
} | ||
|
||
// BC for PHP 7.3 and lower | ||
if (!$validEncoding) { | ||
throw new \ValueError(sprintf('mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self::mb_internal_encoding()
performs validation checks when setting internal values, so adding a try-catch
to the else
avoids a small amount of overhead. What do you think?
} | |
try { | |
$validEncoding = @self::mb_check_encoding('', $encoding); | |
} catch (\ValueError $e) { | |
throw new \ValueError(sprintf('mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); | |
} | |
// BC for PHP 7.3 and lower | |
if (!$validEncoding) { | |
throw new \ValueError(sprintf('mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); | |
} | |
} else { | |
try { | |
$validEncoding = @self::mb_check_encoding('', $encoding); | |
} catch (\ValueError $e) { | |
throw new \ValueError(sprintf('mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); | |
} | |
// BC for PHP 7.3 and lower | |
if (!$validEncoding) { | |
throw new \ValueError(sprintf('mb_ucfirst(): Argument #2 ($encoding) must be a valid encoding, "%s" given', $encoding)); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right I understand the else
block would avoid the non-null calls.i tried to follow the rest of the polyfill methods, so I'd prefer to keep this one like it is now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this code can be condensed by combining it into a method like self::assertEncoding()
. Let's try another PR.
Adds polyfills for `mb_ucfirst` and `mb_lcfirst` functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, calls `mb_convert_case` with `MB_CASE_TITLE` or `MB_CASE_LOWER`, and returns with the concat of the remaining string. The tests are taken from the php-src PR. - [RFC](https://wiki.php.net/rfc/mb_ucfirst) - [php-src PR: php-src#13161](php/php-src#13161) - [PHP.Watch - PHP 8.4: New `mb_ucfirst` and `mb_lcfirst` functions](https://php.watch/versions/8.4/mb_ucfirst-mb_ucfirst) Co-authored-by: USAMI Kenta <tadsan@zonu.me>
dc01ec2
to
5bd65b7
Compare
Thanks a lot for the review @zonuexe those were great. I addressed all the points except the |
Thank you @Ayesh. |
Adds polyfills for
mb_ucfirst
andmb_lcfirst
functions based on the polyfill shown in PHP.Watch. It basically takes the first mb character, callsmb_convert_case
withMB_CASE_TITLE
orMB_CASE_LOWER
, and returns with the concat of the remaining string.The tests are taken from the php-src PR.
mb_ucfirst
andmb_lcfirst
functions