Bug #78609 [Ver->Csd]: mb_check_encoding() doesn't support objects with __toString() method any more

From: Date: Mon, 30 Sep 2019 07:50:11 +0000
Subject: Bug #78609 [Ver->Csd]: mb_check_encoding() doesn't support objects with __toString() method any more
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222952@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78609&edit=1 ID: 78609 Updated by: salathe@php.net Reported by: kurt at suvaline dot com Summary: mb_check_encoding() doesn't support objects with __toString() method any more -Status: Verified +Status: Closed Type: Bug Package: mbstring related Operating System: Linux PHP Version: 7.2 Block user comment: N Private report: N New Comment: Automatic comment on behalf of cmb Revision: http://git.php.net/?p=doc/en.git;a=commit;h=463210b7775cc2c8e59c8139ae529c2085a33154 Log: Fix #78609: mb_check_encoding() no longer supports stringable objects Previous Comments: ------------------------------------------------------------------------ [2019-09-30 07:45:19] cmb@php.net Automatic comment from SVN on behalf of cmb Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=348104 Log: Fix #78609: mb_check_encoding() no longer supports stringable objects ------------------------------------------------------------------------ [2019-09-29 13:45:03] cmb@php.net Confirmed: <https://3v4l.org/tRJm3>. ------------------------------------------------------------------------ [2019-09-29 13:19:06] kurt at suvaline dot com 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 this bug report at https://bugs.php.net/bug.php?id=78609&edit=1

« previous php.bugs (#222952) next »