Bug #78609 [NEW]: mb_check_encoding() doesn't support objects with __toString() method any more
| From: | kurt at suvaline dot com | Date: | Sun, 29 Sep 2019 13:19:06 +0000 |
| Subject: | Bug #78609 [NEW]: mb_check_encoding() doesn't support objects with __toString() method any more | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-222945@lists.php.net to get a copy of this message | ||
From: kurt at suvaline dot com
Operating system: Linux
PHP version: 7.3.10
Package: mbstring related
Bug Type: Bug
Bug description:mb_check_encoding() doesn't support objects with __toString() method any more
Description:
------------
mb_check_encoding() takes either string or array as first parameter. It
seems that with added support for arrays we might have lost the ability
to provide objects with __toString() methods as input. I would expect
that when object of a class having __toString() method is provided as
input for mb_check_encoding() then the result of __toString() will be
used. Instead we currently get the following warning: Warning:
mb_check_encoding(): Input is something other than scalar or array in
/sandbox/mb-check-encoding-invalid-input.php on line 11
Possible related commit:
https://github.com/php/php-src/commit/b651b967383082de0f9c15ad6fcb36dda4082b0d
Possible related part of code:
https://github.com/php/php-src/blob/5d6e923d46a89fe9cd8fb6c3a6da675aa67197b4/ext/mbstring/mbstring.c#L4823-L4844
P.S. Also take note that documentation at
https://www.php.net/manual/en/function.mb-check-encoding.php
does not
mention array as being supported first argument type.
Test script:
---------------
<?php
class Foo
{
public function __toString()
{
return 'string_representation';
}
}
mb_check_encoding(new Foo, 'UTF-8');
Expected result:
----------------
Script runs in both PHP 7.1.32 and PHP 7.3.9 without warnings. When we
remove __toString() method then we get warnings in both PHP versions.
Actual result:
--------------
Script runs without warnings in PHP 7.1.32 but gives (unexpected)
warning "Input is something other than scalar or array" in PHP 7.3.9.
When we remove __toString() method then PHP 7.1.32 gives warning
"mb_check_encoding() expects parameter 1 to be string, object given" and
PHP 7.3.9 gives warning "Input is something other than scalar or array"
--
Edit bug report at https://bugs.php.net/bug.php?id=78609&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78609&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78609&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78609&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78609&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78609&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78609&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78609&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78609&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78609&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78609&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78609&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78609&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78609&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78609&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78609&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78609&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78609&r=mysqlcfg