-1

Given line:

"$className = "MForm" . preg_replace('/(?:^|_)(.?)/e',"strtoupper('$1')",$name);" 

isn't working with PHP7. I changed it to:

"$className = "MForm" . preg_replace_callback('/(?:^|_)(.?)/',"strtoupper('$1')",$name);" 

It seems not to be correct, due to warning printout:

"Warning: preg_replace_callback(): Requires argument 2, 'strtoupper('$1')', to be a valid callback in /.../components/com_proforms/formlib/init.php on line 59"

How can I handle strtoupper('$1') correctly in preg_replace_callback()?

  • You need to pass the name of a function so that it can be executed later. Whereas Ylyou're passing the _result_ of already executing that function. https://www.php.net/manual/en/language.types.callable.php – ADyson Apr 03 '21 at 10:07

1 Answers1

1

Replace "strtoupper('$1')" with

function($matches) { return strtoupper($matches[1]); }

No quotes around it.

dehart
  • 1,554
  • 15
  • 18