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 8727865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:31:10+00:00 2026-06-13T08:31:10+00:00

I have a cakephp application, in one of my controllers, I have a function

  • 0

I have a cakephp application, in one of my controllers, I have a function _filter_callback to be used as callback to the php function array_filter() like this:

class TestClassController extends AppController
{
     var $name = 'TestClass';

     ....

     function test_fn()
     {
         ...
         array_filter($my_array, '_filter_callback');
     }

     function _filter_callback($val)
     {
          // callback logic here...
     }
}

The problem I have is that my function _filter_callback cannot be found by array_filter in my controller because I get the following error:

Warning: array_filter() expects parameter 2 to be a valid callback, 
function '_filter_callback' not found or invalid function name

Does anybody know how I can make array_filter aware of my callback function in a cakephp application?

  • 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-13T08:31:11+00:00Added an answer on June 13, 2026 at 8:31 am

    Is the function in the global scope? If not – it has to be.
    If the body of the function is simple (in most cases) try to use anonymous functions as of PHP > 5.3 – http://php.net/manual/en/functions.anonymous.php

    or use the create_function

    http://php.net/manual/en/function.create-function.php

    You can then inject this as a parameter without declaring one-use global function.

    Example of filtering all elements smaller than 10:

    array_filter($array, create_function('$a', 'return $a > 10;'));
    

    EDIT:
    I can see now that you are trying to call method of the object. You must specify the instance. Try this:

    array_filter($my_array, array($this, '_filter_callback'));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my CakePHP application, I have a model like this: class Duck extends AppModel
In my CakePHP application, I have a view with this markup: <div class=copy id=share-copy></div>
So I have this one CakePHP web application that I'm trying to refactor. There
I have been busy integrating Wordpress to one of a CakePHP application.Last Monday I
I'm developing a application with CakePHP, and I have two layouts: one for the
I develop a back-end for a mobile application with cakephp I have a function
I have to run my CakePHP 2.1 application in an environment with CGI-PHP and
I have an application that used another php cms system, which I am now
I have two issues with my CakePHP application (its my first one in CakePHP).
I have an existing PHP/MySQL application that I want to convert over to CakePHP.

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.