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

mb_strlen exists but mb_check_encoding undefined #75

Closed
korobochkin opened this issue Oct 24, 2016 · 9 comments
Closed

mb_strlen exists but mb_check_encoding undefined #75

korobochkin opened this issue Oct 24, 2016 · 9 comments

Comments

@korobochkin
Copy link

korobochkin commented Oct 24, 2016

Hi. I trying to use this amazing library in my work but still not understand what happens. I manually disable mbstring module in my php-7 setup for testing purposes. But all of this functions from this library still not defined.

I debug into the bootstrap.php and see that function_exists('mb_strlen') returns true. I hope that I'm doing something wrong but I can't explain that happening.

Why mb_strlen() defined if mbstring module is disabled?

$exists = function_exists('mb_strlen');
(bool)true

$phpVersion = phpversion();
7.0.12-1+deb.sury.org~trusty+1

$extensions = get_loaded_extensions();
array (
  0 => 'Core',
  1 => 'date',
  2 => 'libxml',
  3 => 'openssl',
  4 => 'pcre',
  5 => 'zlib',
  6 => 'filter',
  7 => 'hash',
  8 => 'Reflection',
  9 => 'SPL',
  10 => 'session',
  11 => 'standard',
  12 => 'cgi-fcgi',
  13 => 'mysqlnd',
  14 => 'PDO',
  15 => 'xml',
  16 => 'bcmath',
  17 => 'calendar',
  18 => 'ctype',
  19 => 'curl',
  20 => 'dom',
  21 => 'exif',
  22 => 'fileinfo',
  23 => 'ftp',
  24 => 'gd',
  25 => 'gettext',
  26 => 'iconv',
  27 => 'imagick',
  28 => 'imap',
  29 => 'json',
  30 => 'mcrypt',
  31 => 'memcache',
  32 => 'mysqli',
  33 => 'pdo_mysql',
  34 => 'Phar',
  35 => 'posix',
  36 => 'readline',
  37 => 'shmop',
  38 => 'SimpleXML',
  39 => 'soap',
  40 => 'sockets',
  41 => 'ssh2',
  42 => 'sysvmsg',
  43 => 'sysvsem',
  44 => 'sysvshm',
  45 => 'tokenizer',
  46 => 'wddx',
  47 => 'xmlreader',
  48 => 'xmlwriter',
  49 => 'xsl',
  50 => 'zip',
  51 => 'Zend OPcache',
  52 => 'xdebug',
)
@keradus
Copy link
Member

keradus commented Oct 24, 2016

but all of this functions from this library still not defined.
I debug into the bootstrap.php and see that function_exists('mb_strlen'); returns true

so, your PHP claims it knows about mb_strlen function, so polyfill is working properly for you. The method is registered not by module, but via this polyfill.

@korobochkin
Copy link
Author

@keradus yes, I expect this behaviour. But instead I have fatal error :

Fatal error: Uncaught Error: Call to undefined function Symfony\Component\Validator\Constraints\mb_check_encoding() in /srv/www/wordpress-default/wp-content/plugins/setka-editor/vendor/symfony/validator/Constraints/LengthValidator.php on line 42

The code from my first message I writed directly in bootstrap.php before if (!function_exists('mb_strlen')). So right in bootstrap.php function_exists('mb_strlen') returns true but all of this functions such as mb_check_encoding() not defined because I don't have an extension (manually disabled) and if (!function_exists('mb_strlen')) statement working not as expected.

@korobochkin
Copy link
Author

Ah!. I understand what it is. As you can noticed before - I'm using this libraby (Symfony Validator) in WordPress. And WordPress have their own mb_strlen() in wp-includes/compat.php:

if ( ! function_exists( 'mb_strlen' ) ) :
    function mb_strlen( $str, $encoding = null ) {
        return _mb_strlen( $str, $encoding );
    }
endif;

Oh! Look like I'm in trouble :)

@keradus
Copy link
Member

keradus commented Oct 24, 2016

keradus@keradus:~$ php --version
PHP 7.1.0RC3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.1.0RC3, Copyright (c) 1999-2016, by Zend Technologies
keradus@keradus:~$ php -m | grep mb
keradus@keradus:~$ php -r "var_dump(function_exists('mb_strlen'));"
bool(false)

@keradus
Copy link
Member

keradus commented Oct 24, 2016

buahahaha :D good one ;)
maybe you should propose WP to use this polyfill, as it's more full ? (eg we have that mb_check_encoding)

@korobochkin
Copy link
Author

@keradus Thank you for your suggestions :) Spent a few hours to prepare server with PHP 7.0 and all the environment similar to the "bug reported environment". And only after it thought to search for function mb_strlen in WordPress source code :)

I'd really like to WordPress used this and other Symfony packages (librarys) but it takes a long time for developement and older WordPress versions still unmodified (its bad for plugin developers who cares about backward compatibility).

@keradus
Copy link
Member

keradus commented Oct 24, 2016

well. one way or another I think that this issue could be closed.

@korobochkin
Copy link
Author

Yes. Thank you for quick replies and support!

@keradus
Copy link
Member

keradus commented Oct 24, 2016

glad to help !

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

No branches or pull requests

2 participants