How to fix an error in a php that uses mbstring?

17 views Asked by At

I am reviewing a web page running multiple php on a machine with Linux Debian.

Specifically, one of the php contains this code:

$methods = get_class_methods ( $class );
// Makes the content of $methods to be:
// $methods = ["__construct", "getId", "setId", "getVal", "setVal"]

$plength = count($methods);

for($i=0;$i<$plength;$i++) {
  if(stripos($methods[$i], "get")!==FALSE){
    $property = mb_substr($methods[$i], 3, mb_strlen($methods[$i], 'UTF-8'), 'UTF-8');
    $setter = 'set'.mb_substr($methods[$i], 3, mb_strlen($methods[$i], 'UTF-8'), 'UTF-8');

    // ...  
  }
}

When executing this php in the web browser, the error is displayed:

Error Call to undefined function mb_substr()

indicating that the line that produces the error is the one that begins with

$property =

I have searched for information in various forums about this error and I have seen that it is due to the fact that mbstring is an extension that is not installed by default.

Running the command

php -m | grep mbstring

I check that mbstring is not installed, so it is necessary to install it.

So I have checked what version of php I have:

php -v

It shows that the installed version of php is 7.4.28

And then I install mbstring with:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php7.4-mbstring

Now the command

php -m | grep mbstring

shows mbstring

However, the web browser still shows the same error than before:

Error Call to undefined function mb_substr()

indicating that the line that produces the error is the one that begins with

$property =

I do not understand why it keeps showing this error if now mbstring is installed.

Would it be possible to modify the source code of the php so that it uses native php functions that don't require install anything extra (that doesn't use mbstring) ?

0

There are 0 answers