Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:45:09+00:00 2026-06-06T06:45:09+00:00

Warning: preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, ‘info’, to be a valid callback in […]

  • 0

Warning: preg_replace_callback() [function.preg-replace-callback]: Requires argument 2, ‘info’, to be a valid callback in […]

public function getDisplay(){
    $info = array_merge($this->info,array());

    return  preg_replace_callback('!\{\{(\w+)\}\}!', 'info', $this->display);
}

In a public function from “MyClass”, stopped working when I moved from another class to this one. Which was:

public function getEdit( $type){
    $all_info = $this->info;

    return preg_replace_callback('!\{\{(\w+)\}\}!', 'all_info', $edit_contents);
}

Both are cleaned up, and now I can’t retest with previous class because it’s already long gone.

I’m sure using variables is not allowed, but it was working, so I’m clueless.

When I do this, as suggested in some stackoverflow thread, but obviously it’s not made to be used within objects:

public function getDisplay(){
    $display_info = $this->info;

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

    return  preg_replace_callback('!\{\{(\w+)\}\}!', 'display_info', $this->display);
}

So I need some love and guidance cuz php is driving me crazy this week…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:45:11+00:00Added an answer on June 6, 2026 at 6:45 am

    The correct way to do this would be with a closure:

    public function getDisplay() {
    
        // While $this support in closures has been recently added (>=5.4.0), it's
        // not yet widely available, so we'll get another reference to the current
        // instance into $that first:
        $that = $this;
    
        // Now we'll write that preg... line of which you speak, with a closure:
        return  preg_replace_callback('!\{\{(\w+)\}\}!', function($matches) use($that) {
            return $that->info[$matches[1]];
        }, $this->display);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a PHP warning message below Warning: preg_replace() [function.preg-replace]: Compilation failed: POSIX collating
I keep getting this error: Warning: preg_match() [function.preg-match]: Unknown modifier 't' in D:\xampp\htdocs\administrator\components\com_smms\functions\plugin.php on
Warning: preg_match_all() [function.preg-match-all]: Unknown modifier 'l' in /var/www/test.php on line 9 It's saying my
I'm getting the following error [13-Sep-2011 07:26:28] PHP Warning: preg_match_all() [<a href='function.preg-match-all'>function.preg-match-all</a>]: Unknown modifier
Warning: touch() [function.touch]: open_basedir restriction in effect. File() is not within the allowed path(s):
Warning: imap_open() [function.imap-open]: Couldn't open stream {imap.gmail.com:993/imap/ssl}INBOX in /home/happy/public_html/source/imap/fet_mail_from_email_add.php on line 7 can't connect:
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast and
I'm going through my code to replace any instances I'm using the ereg() function
When I run the below: $MATH_REGEX = '/(?=(?<!\\)\$).(.+?)(?<!\\)\$/'; preg_replace_callback($MATH_REGEX, function ($match) { $latex_code =
Warning: Note that this is a dumb question of something that I would probably

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.