【问题标题】:Call to undefined function yii\helpers\mb_strlen() even though mbstring is enabled调用未定义函数 yii\helpers\mb_strlen() 即使启用了 mbstring
【发布时间】:2015-08-06 06:19:04
【问题描述】:

我在 php.ini 中启用了 mbstring。它甚至显示在 phpinfo() 中。但我仍然在 yii2 中收到此错误。

PHP Fatal Error 'yii\base\ErrorException' with message 'Call to undefined function yii\helpers\mb_strlen()

【问题讨论】:

  • mb_strlen 是一个全局 PHP 函数,为什么要在 yii\helpers\ 命名空间中搜索呢?
  • 请贴出代码!
  • 试试\mb_strlen()

标签: yii2 mbstring


【解决方案1】:

正如@TomaszKane 在评论中所说,mb_strlen() 是原生 PHP 函数,因此您需要将其调用为 mbstrlen() 而无需指定命名空间。

官方文档:

另外看看yii\helpers\StringHelpermb_strlen()在几个地方都用到了。例如,如果你正在寻找字节长度,有一个特殊的方法byteLength(),你可以这样调用它:

use yii\helpers\StringHelper;

...

StringHelper::byteLength($string);

基本上是mb_strlen()的语法糖。

【讨论】:

  • 是的,它在 byteLength() 中使用,这就是它抛出错误的原因。我没有在任何地方使用它,错误在 yii2 的基本文件中,即 StringHelper。
猜你喜欢
  • 1970-01-01
  • 2023-03-17
  • 2018-03-12
  • 2021-08-07
  • 1970-01-01
  • 2012-01-06
  • 1970-01-01
  • 2017-04-09
  • 1970-01-01
相关资源
最近更新 更多